#!/usr/bin/perl package HTC::Object; use strict; use warnings; use base qw(Class::Accessor); __PACKAGE__->follow_best_practice; __PACKAGE__->mk_accessors(qw(first last age)); package main; use strict; use warnings; use HTML::Template::Compiled; use Fcntl qw(:seek); my ($template, $perlcode); { local $/; $template = ; seek DATA, 0, SEEK_SET; $perlcode = ; } my $htc = HTML::Template::Compiled->new( scalarref => \$template, tagstyle => [qw(+tt)], formatter => { 'HTC::Object' => { fullname => sub { my $first = $_[0]->get_first; my $last = $_[0]->get_last; return "$last, $first"; }, }, }, ); my $persons = [ HTC::Object->new({first => 'Bart', last => 'Simpson', age => 10}), HTC::Object->new({first => 'Maggie', last => 'Simpson', age => 10}), HTC::Object->new({first => 'March', last => 'Simpson', age => 42}), HTC::Object->new({first => 'Homer', last => 'Simpson', age => 42}), ]; $htc->param( count => scalar @$persons, items => $persons, script => $0, perlcode => $perlcode, ); my $output = $htc->output; print $output; __DATA__ HTC example with objects

Script: [%= .script %]

Found [%= .count %] persons: [%loop items%] [%/loop items%]
NameAge
[%= _/fullname %] [%= get_age %]


The Script:

[%= perlcode escape=html %]