Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

class::makemethods::utility::textbuilder(3pm) [debian man page]

MakeMethods::Utility::TextBuilder(3pm)			User Contributed Perl Documentation		    MakeMethods::Utility::TextBuilder(3pm)

NAME
Class::MakeMethods::Utility::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: o A string, in which any '*' characters will be replaced by the base text. The interpolated string then replaces the base text. o A code-ref, which will be called with the base text as its only argument. The result of that call then replaces the base text. o A hash-ref, which will be added to the substitution hash used in the second pass, below. o An array-ref, containing additional expressions to be treated as above. 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: o 'string' => 'string' Occurances of the first string are to be replaced by the second. o 'string' => code_ref Occurances of the string are to be replaced by the results of calling the subroutine with no arguments. o 'string{}' => 'string' Occurances of the first string and subsequent block of braces are replaced by a copy of the second string in which any '*' characters have first been replaced by the contents of the brace block. o 'string{}' => code_ref Occurances of the string and subsequent block of braces are replaced by the results of calling the subroutine with the contents of the brace block as its only argument. o 'string{}' => hash_ref Occurances of the string and subsequent block of braces are replaced by using the contents of the brace block as a key into the provided hash-ref. EXAMPLE
The following text and modification rules provides a skeleton for a collection letter: my $letter = "You owe us AMOUNT. Please pay up! " . "THREAT{SEVERITY}"; my @exprs = ( "Dear NAMEm *", "* -- The Management", { 'THREAT{}' => { 'good'=>'Please?', 'bad'=>'Or else!' } }, " DATE *", { '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 Class::MakeMethods for general information about this distribution. perl v5.10.1 2004-09-06 MakeMethods::Utility::TextBuilder(3pm)

Check Out this Related Man Page

MakeMethods::Composite::Universal(3pm)			User Contributed Perl Documentation		    MakeMethods::Composite::Universal(3pm)

NAME
Class::MakeMethods::Composite::Universal - Composite Method Tricks SYNOPSIS
Class::MakeMethods::Composite::Universal->make_patch( -TargetClass => 'SomeClass::OverYonder', name => 'foo', pre_rules => [ sub { my $method = pop; warn "Arguments for foo:", @_ } ] post_rules => [ sub { warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults } ] ); DESCRIPTION
The Composite::Universal suclass of MakeMethods provides some generally-applicable types of methods based on Class::MakeMethods::Composite. METHOD GENERATOR TYPES
patch The patch ruleset generates composites whose core behavior is based on an existing subroutine. Here's a sample usage: sub foo { my $count = shift; return 'foo' x $count; } Class::MakeMethods::Composite::Universal->make( -ForceInstall => 1, patch => { name => 'foo', pre_rules => [ sub { my $method = pop @_; if ( ! scalar @_ ) { @{ $method->{args} } = ( 2 ); } }, sub { my $method = pop @_; my $count = shift; if ( $count > 99 ) { Carp::confess "Won't foo '$count' -- that's too many!" } }, ], post_rules => [ sub { my $method = pop @_; if ( ref $method->{result} eq 'SCALAR' ) { ${ $method->{result} } =~ s/oof/oozle-f/g; } elsif ( ref $method->{result} eq 'ARRAY' ) { map { s/oof/oozle-f/g } @{ $method->{result} }; } } ], }, ); make_patch A convenient wrapper for "make()" and the "patch" method generator. Provides the '-ForceInstall' flag, which is required to ensure that the patched subroutine replaces the original. For example, one could add logging to an existing method as follows: Class::MakeMethods::Composite::Universal->make_patch( -TargetClass => 'SomeClass::OverYonder', name => 'foo', pre_rules => [ sub { my $method = pop; warn "Arguments for foo:", @_ } ] post_rules => [ sub { warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults } ] ); SEE ALSO
See Class::MakeMethods for general information about this distribution. See Class::MakeMethods::Composite for more about this family of subclasses. perl v5.10.1 2004-09-06 MakeMethods::Composite::Universal(3pm)
Man Page