NAME

Text::Template::Simple - A simple template class mainly for web applications.

SYNOPSIS

use Text::Template::Simple;

my $template = Text::Template::Simple->new(
   delimiters => ['{', '}'],
   globals => {
      foo  => 'bar'  , # define $foo
      bar  => ['baz'], # define @bar
      blah => {        # define %blah
         key => 'value',
      },
   },
   dummy => "MY::Dummy::Class::To::Fill::In::Templates",
   # reset_dummy => 1, # reset dummy class' symbol table explicitly
 );

my $result = $template->compile(
               'Hello {$foo}. Key is: {$blah{key}} and Your name is {$name}.',
               {
                  name => 'Burak',
               });
print $result;

DESCRIPTION

This module provides a simple and high level access to Text::Template modules interface. It also adds a PREPEND parameter to enable strict mode and define the variables before using them. If your perl version is smaller than 5.6; the vars pragma, and if it is greater; our function will be used to define variables in the template. Main purpose of this module is to setup that variable definiton code and itialize all variables if any on them has the value undef.

METHODS

new

The object constructor. Takes several parameters:

delimiters

The default delimiter set is: <% %>. You can pass you own delimiters as an arrayref:

Text::Template::Simple->new(
   delimiters => ['{', '}'],
)

global

You can define variables that are globally accessible by all templates.

Example:

$globals = {
      foo  => 'bar'  , # define $foo
      bar  => ['baz'], # define @bar
      blah => {        # define %blah
         key => 'value',
      },
};

Text::Template::Simple->new(
   globals => $globals,
)

dummy

This must be a dummy package/class name. The module will compile the template into this class. If you don't set it, the default class Text::Template::Simple::Dummy will be used.

compile TEMPLATE, PARAMS

Compiles the template into its final form. Takes two paramters. First parameter is the raw template code as a string and second is the parameters you can set. PARAMS must be a HASHREF.

my $result = $template->compile('Your name is {$name}.',
               {
                  name => 'Burak', # set $name
               });

BUGS

Complete interface of Text::Template is not supported.
Parameter names can not start with minus

Example: -dummy or -Dummy is unvalid. Use dummy or Dummy or DUMMY etc...

Only single string data is accepted as a template text

Filehandles and any other things are not supported. You must supply a single text parameter as the template code.

SAFE, BROKEN_ARG and friends are not supported.

Many paramaters to Text::Template is not supported.

There may be many more... Please report if you find any bugs.

SEE ALSO

Text::Template.

AUTHOR

Burak Gürsoy, <burak@cpan.org>

COPYRIGHT

Copyright 2004 Burak Gürsoy. All rights reserved.

LICENSE

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

1 POD Error

The following errors were encountered while parsing the POD:

Around line 243:

Non-ASCII character seen before =encoding in 'Gürsoy,'. Assuming CP1252