Class::MakeMethods::Template::TextBuilder - Basic text substitutions


NAME

Class::MakeMethods::Template::TextBuilder - Basic text substitutions


SYNOPSIS

 print text_builder( $base_text, @exprs )


DESCRIPTION

This module provides a single function, which implements a simple ``text macro'' mechanism for assembling templated text strings.

  $expanded_text = text_builder( $base_text, @exprs )

Returns a modified copy of $base_text using rules from the @exprs list.

The @exprs list may contain any of the following:

After any initial string and code-ref rules have been applied, the hash of substitution rules are applied.

The text will be searched for occurances of the keys of the substitution hash, which will be modified based on the corresponding value in the hash. If the substitution key ends with '{}', the search will also match a balanced block of braces, and that value will also be used in the substitution.

The hash-ref may contain the following types of rules:


EXAMPLE

The following text and modification rules provides a skeleton for a collection letter:

  my $letter = "You owe us AMOUNT. Please pay up!\n\n" . 
                  "THREAT{SEVERITY}";

  my @exprs = (
    "Dear NAMEm\n\n*",
    "*\n\n-- The Management",

    { 'THREAT{}' => { 'good'=>'Please?', 'bad'=>'Or else!' } },

    "\t\t\t\tDATE\n*",
    { 'DATE' => 'Tuesday, April 1, 2001' },
  );

One might invoke this template by providing additional data for a given instance and calling the text_builder function:


  my $item = { 'NAME'=>'John', 'AMOUNT'=>'200 camels', 'SEVERITY'=>'bad' };

  print text_builder( $letter, @exprs, $item );

The resulting output is shown below:

                                  Tuesday, April 1, 2001
  Dear John,

  You owe us 200 camels. Please pay up!

  Or else!

  -- The Management


SEE ALSO

See the Class::MakeMethods manpage for general information about this distribution.

 Class::MakeMethods::Template::TextBuilder - Basic text substitutions