Template::Like - Lightweight Template Engine.


Template-Like documentation Contained in the Template-Like distribution.

Index


Code Index:

NAME

Top

Template::Like - Lightweight Template Engine.

SYNOPSIS

Top

    #!/usr/bin/perl

    use lib 'lib';
    use strict;
    use Template::Like;

    my $input = q{
    [% var %]
    [% FOREACH var = vars %]
    - [% var.name %]
    [% END %]
    [% var %]
    [% IF bool %]TURE!![% ELSE %]FALSE!![% END %]
    [% UNLESS bool %]TURE!![% ELSE %]FALSE!![% END %]
    };

    my $param = {
      var  => "HOGE",
      vars => [ { name => "FOO" }, { name => "BAR" } ],
      bool => 1
    };

    my $t = Template::Like->new;

    my $output = "";

    $t->process(\$input, $param, \$output);

    print $output;

    exit;




result



    HOGE

    - FOO

    - BAR

    HOGE
    TURE!!
    FALSE!!




DESCRIPTION

Top

Directive

GET
SET
USE
CALL
FOREACH
WHILE
IF
UNLESS
ELSIF
ELSE
END
FILTER
DUMMY
INSERT
INCLUDE
PROCESS

VMethods

scalar

defined
length
repeat
replace
match
split
list
hash
size
substr
html
uri

array

first
last
size
max
reverse
join
grep
sort
nsort
unshift
push
shift
pop
unique
merge
slice
splice
list

hash

keys
values
each
defined
exists
size
item
list

official http://www.template-like.org

SEE ALSO

Top

Template

AUTHOR

Top

Shinichiro Aska, <askadna@cpan.org>

COPYRIGHT AND LICENSE

Top


Template-Like documentation Contained in the Template-Like distribution.

package Template::Like;

use strict;
use File::Spec;
use IO::File;

use Template::Like::Processor;

$Template::Like::VERSION = '0.11';

#=====================================================================
# new
#---------------------------------------------------------------------
# - API
# $instance = Template::Like->new( %option )
#---------------------------------------------------------------------
# - args
# %option ... see also pod. ( HASHREF )
#---------------------------------------------------------------------
# - Example
# my $t = Template::Like->new( TAG_STYLE => 'asp' );
#=====================================================================
sub new {
  my $class = shift;
  
  my $self  = bless {
    OPTION => ref $_[0] ? $_[0] : { @_ },
  }, $class;
  
  return $self;
}



#=====================================================================
# process
#---------------------------------------------------------------------
# - API
# $rc = $t->process( $input, $params, $output, $option );
#---------------------------------------------------------------------
# - args
# $input  ... INPUT  ( SCALAR, SCALARREF, ARRAYREF, HASHREF, GLOB )
# $params ... PARAMS ( HASHREF )
# $output ... OUTPUT ( SCALAR, SCALARREF, ARRAYREF, HASHREF, GLOB, Apache::Request )
# $option ... see also pod. ( HASHREF )
#---------------------------------------------------------------------
# - Example
# $t->process( $input, $params, $output, $option ) || die $t->error();
#=====================================================================
sub process {
  my $self = shift;
  my $input  = shift || undef;
  my $params = shift || {};
  my $output = shift || undef;
  my $option = shift || {};
  
  eval {
    my $processor = Template::Like::Processor->new( $self->_option, $params, $option );
    
    $processor->finalize( $processor->process( $input ), $output );
  };
  
  $self->error($@);
  
  die $@ if $@;
  return if $@;
  return 1;
}




#=====================================================================
# error
#---------------------------------------------------------------------
# - API
# $error = $t->error();
#---------------------------------------------------------------------
# - returns
# $error ... Error Message.
#---------------------------------------------------------------------
# - Example
# $t->process( $input, $params, $output, $option ) || die $t->error();
#=====================================================================
sub error  {
  $_[0]->{'ERROR'} = $_[1] if @_ > 1;
  $_[0]->{'ERROR'}; 
}

sub _option { $_[0]->{'OPTION'}; }