The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Template::Perl - a module to evaluate perl code embedded in text.

SYNOPSIS

  use Template::Perl;
  my $t = Template::Perl->new();

  my $template = q{
    Yo nombre es [- $name -].
    I am [- $age -] years old.          
  };

  # initialize a couple vars in package 'main'
  my $name = 'Steve';
  my $age  = 31;

  # parse defaults to package 'main' (unless a hash has been loaded)
  print $t->parse({
      TEXT      => $text
  });

  # or...use a hash ( slower, but easier to work with )

  my %hash = (
    name => 'Steve',
    age  => 31
  );

  print $t->parse({
      TEXT      => $text,
      HASH      => \%hash
  });

  # ...or however you like it, as long as text and hash or package name 
 # is loaded before or when parse() is called.

DESCRIPTION

Template::Perl a module for evaluating perl embedded in text. The perl is evaluated under a package, or under a package built from a hash. This module was built primarily as a demonstration of Parse::Tokens, but it works great.

FUNCTIONS

hash()

$t->hash();

Installs values identified by a given hash reference into a package under which to evaluate perl tokens.

new()

my $t = Template::Perl->new();

Optionally pass a hash reference of FILE, TEXT, PACKAGE, HASH, or DELIMITERS fields.

FILE = valid path (your template) or...

TEXT = block of text (your template)

PACKAGE = name of a package (your data) or...

HASH = hash reference (your data)

DELIMITERS = array reference to left and right delimiters

package()

$t->package('package_name');

Set the package name under which to evaluate extracted perl.

parse()

$t->parse();

Runs the parser. Optionally accepts parameters as specified for new();.

parsed();

$text = $t->parsed();

Returns the fully parsed and evaluated text.

AUTHOR

Steve McKay, steve@colgreen.com

COPYRIGHT

Copyright 2000 Steve McKay. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Parse::Tokens, Text::Template, Text::SimpleTemplate