Text::TagTemplate

Text::TagTemplate is designed to make the process of constructing web-based applications.
Download

Text::TagTemplate Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jacob Davies
  • Publisher web site:
  • http://search.cpan.org/~matisse/Text-TagTemplate-1.83/lib/Text/TagTemplate.pm

Text::TagTemplate Tags


Text::TagTemplate Description

Text::TagTemplate is designed to make the process of constructing web-based applications. Text::TagTemplate is designed to make the process of constructing web-based applications (such as CGI programs and Apache::Registry scripts) much easier, by separating the logic and application development from the HTML coding, and allowing ongoing change This module provides a mechanism for including special HTML-like tags in a file (or scalar) and replacing those tags at run-time with dynamically generated content. For example the special tag < #USERINFO FIELD="favorite_color" >might be replaced by "green" after doing a database lookup. Usually each special tag will have its own subroutine which is executed every time the tag is seen.Each subroutine can be basically anything you might want to do in Perl including database lookups or whatever. You simply create subroutines to return whatever is appropriate for replacing each special tag you create.Attributes in the special tags (such as the FIELD="favorite_color" in the example above) are passed to the matching subroutine.It is not web-specific, though, despite the definite bias that way, and the template-parsing can just as easily be used on any other text documents. The examples here will assume that you are using it for convential CGI applications.It provides functions for parsing strings, and constructing lists of repeated elements (as in the output of a search engine).It is object-oriented, but -- like the CGI module -- it does not require the programmer to use an OO interface. You can just import the ``:standard'' set of methods and use them with no object reference, and it will create and use an internal object automatically. This is the recommended method of using it unless you either need multiple template objects, or you are concerned about namespace pollution.SYNOPSIS use Text::TagTemplate qw( :standard ); # Define a single tag to substitute in a template. add_tag( MYTAG => 'Hello world.' ); # Define several tags all at once. The tags() method wipes out # all current tags. tags( +{ FOO => 'The string foo.', # Single-quoted string BAR => "$ENV{ USER }", # Double-quoted string LIST => join( '< LI >', @list ), # Function call # Functions or subroutines that get called each time # the tag is replaced, possibly producing different # results for the same tag if it appears twice or more. TIME => &time(), # Reference to a function SUB => sub { # Anonymous subroutine my( $params ) = @_; return $params->{ NAME }; } } ); # Add a couple of tags to the existing set. Takes a hash-ref. add_tags( +{ TAG1 => "Hello $ENV{ USER }", TAG2 => rand( 10 ), # random number between 0 and 10 } ); # Set the template file to use. template_file( 'template.htmlt' ); # This is list of items to construct a list from. list( 'One', 'Two', 'Three' ); # These are template-fragment files to use for making the list. entry_file( 'entry.htmlf' ); join_file( 'join.htmlf' ); # This is a callback sub used to make the tags for each entry in a # parsed list. entry_callback( sub { my( $item ) = @_; return +{ ITEM => $item }; } ); # Add a new tag that contains the whole parsed list. add_tag( LIST => parse_list_files ); # Print the template file with substitutions. print parse_file;Requirements:· Perl Requirements: · Perl


Text::TagTemplate Related Software