HTML::Processor HTML Template Processor DESCRIPTION Processor.pm is primarily an HTML template processing utility. It is designed to remove html from perl scripts without putting too much Perl into the html. The tag syntax (configurable) is somewhat verbose in order to not scare off html coders, while retaining some Perl logic and functionality. The Perl interface is OO for flexibility and clarity and has a fairly basic set of methods. While its not as heavy duty as some of the other Template modules, it occupies a firm middle ground with all the essential data replacement funtions. Functionality: - File includes - Optional content - If/Else blocks - Variable substitution - Loops (nested recursively) - Loop Optional content - Loop If/else blocks - Data sorting (columns) - Debugging, Perl and Object data DOCUMENTATION All documentation, with examples, is in Processor.pm, additionally in Processor.html which was generated via pod2html from Processor.pm See also provided example script. EXAMPLE PERL ------------------------------------------------------ use HTML::Processor; $tpl = new HTML::Processor; -or with config options- $tpl = new HTML::Processor ({ debug => "Normal", footprint => 1, clean => 0 }); # data %animals = ( mammals => { types => [qw(monkey lion zebra elephant)], count => 120 }, fish => { types => [qw(swordfish shark guppy tuna marlin tunny)], count => 85 }, reptiles => { types => [qw(monitor python crocodile tortoise)], count => 25 }, birds => { types => [qw(eagle pigeon kite crow owl sparrow)], count => 57 } ); # create parent loop object my $animals = $tpl->new_loop("animals"); foreach my $animal_type( keys %animals){ # add data to the parent loop $animals->array("animal_type", $animal_type); $animals->array("count", $animals{$animal_type}{ count }); # create new nested loop object 'keyed' on # the parent via $animal_type my $types = $tpl->new_loop("types", $animal_type); foreach my $type ( @{ $animals{$animal_type}{types} }){ # populate each 'child' loop $types->array("type", $type); } } # set variables $tpl->variable("what", "ANIMALS"); $tpl->variable("count", 2); # process and print parsed template print $tpl->process("templates/animals.html"); HTML ------------------------------------------------------
[TPL array='animal_type'] [[TPL array='count']] |
[TPL LOOP name='types']
[TPL array='type'] [TPL LOOP END] |
mammals [120] |
monkey lion zebra elephant |
fish [85] |
swordfish shark guppy tuna marlin tunny |
birds [57] |
eagle pigeon kite crow owl sparrow |
reptiles [25] |
monitor python crocodile tortoise |