#!/usr/bin/perl -w use strict; use TemplateM 2.20 'galore'; use CGI; my $q = new CGI; my $tmpl; read DATA, $tmpl, 1000; my $template = new TemplateM( -template => $tmpl, -header => "Content-type: text/html; charset=UTF-8\n\n", ); $template->stash( title => 'TemplateM', version => $template->VERSION, scheme => uc($template->scheme) ); my @headers = qw/ NUMBER NAME DATA /; my @peoples = ( [ 12, 'Andy Wayment', ['wandy@foo.bar', '+1123-456-789'] ], [ 45, 'Klaus Festiwal', ['fklaus@foo.bar'] ], [ 250, 'Tommi Lee', ['ltommi@foo.bar', '+1123-789-456', 'CANADA'] ], [ 269, 'Klaus Maine', ['mklaus@foo.bar', '+4254-133-845', 'GERMANY'] ] ); $template->stash(head1 => 'Peoples:'); my $hs = $template->start('headers'); foreach (@headers) { $hs->loop(h => $_) } $hs->finish; my $peoples = $template->start('peoples'); foreach my $p (@peoples) { $peoples->loop( number => $p->[0], name => $p->[1]); my $data = $peoples->start('data'); my $i = 0; my $c = $#{$p->[2]} ; foreach my $d (@{$p->[2]}) { $data->loop(string => $d); $data->ifelse('hr', $i != $c); $i++; } $data->finish; } $peoples->finish; $template->stash(head2 => 'Code:'); open CODEF, __FILE__; my $code; read CODEF, $code, 3000; $template->stash(code => $q->escapeHTML($code)); close CODEF; print $template->html(); exit; __END__
|
|