NAME Template::Plex - Templates in (P)erl using (Lex)ical Aliasing SYNOPSIS Import "plex" and "plx" into you package: use Template::Plex; Setup variables/data you want to alias: my $vars={ size=>"large", slices=>8, people=>[qw ] }; local $"=", "; Write a template: #Contents of my_template.plex Ordered a $size pizza with $slices slices to share between @$people and myself. That averages @{[$slices/(@$people+1)]} slices each. Load the template with "plex": my $template= plex "my_template.plex", \%vars; Render it: my $output=$template->render; #OUTPUT Ordered a large pizza with 8 slices to share between Kim, Sam, Harry, Sally and myself. That averages 1.6 slices each. Change values and render it again: $vars->{size}="extra large"; $vars->{slices}=12; $output=$template->render; #OUTPUT Ordered a extra large pizza with 12 slices to share between Kim, Sam, Harry, Sally and myself. That averages 2.4 slices each. DESCRIPTION This module facilitates the use of perl (not embedded perl) as a text processing template language and system capable of loading, caching and rendering powerful templates. It does this by implementing a handful of subroutines to perform template loading/management (i.e. "plex" and "plx") and also includes a couple of convenience routines to make processing simpler (i.e. "block" and "jmap"). String::Util string filtering routines are also made available in templates for the most common of filtering tasks. Of course you can "use" any modules you like within the template, or define your own subroutines within the template. The template is just perl! Conceptually, a "Template::Plex" template is just a string in perl's double quoted context, with the outer operators removed: #PERL "This is a perl string interpolating @{[ map uc, qw]}" # or qq{This is a perl string interpolating @{[ map uc, qw]}} #PLEX template. Same as PERL syntax, without the outer double quotes This is a perl string interpolating @{[ map uc, qw]}; #OUTPUT is the same for all of the above: This is a perl string interpolating A B C D The 'lexical' part of this modules refers to ability of variables to be aliased into the template (more on this later). It improves the style and usage of variables in a template while also allowing sub templates to access/override variables using lexical scoping. The synopsis example only scratches the surface in terms of what is possible. For more examples, checkout the examples directory in this distribution. I hope to add more in the future FEATURES The following are snippets of templates demonstrating some of the feature: * Templates are written in perl syntax: This template is a valid $perl code @{[ uc "minus" ]} the outer quotes * Templates are compiled into a perl subroutine, with automatic caching (plx) Sub/template is loaded only the first time in this map/loop @{[map {plx "path_to_template",{}} qw< a b c d e >]} * Lexical and package variables accessed/created within templates @{[ block { $input_var//=1; #set default } }] Value is $input_var; * Call and create subroutines within templates: @{[ block { sub my_great_calc { my $input=shift; $input*2/5; } } }] Result of calculation: @{[my_great_calc(12)]} * 'Include' Templates within templates easily: @{[include("path_to_file")]} * Recursive sub template loading @{[ plx "path_to_sub_template" ]} * Conditional rendering @{[ $flag and $var]} @{[ $flag?$var:""]} @{[ pl { if($flag){ #do stuff } } ]} * Lists/Loops/maps template interpolates @$lists directly Items that are ok: @{[ do { #Standard for loop my $output; for(@$items){ $output.=$_."\n" if /ok/; } $output; } }] More ok items: @{[map {/ok/?"$_\n":()} @$items]} * "use" other modules directly in templates: @{[ block { use Time::HiRes qw