Text::Macros

An object-oriented text macro engine
Download

Text::Macros Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • John Douglas Porter
  • Publisher web site:
  • http://search.cpan.org/~jdporter/

Text::Macros Tags


Text::Macros Description

An object-oriented text macro engine Text::Macros.pm is a Perl object-oriented text macro engine.Typical usage might look like this: my $template = $account_num ); # make a macro expander: my $macro_expander = Text::Macros->new( "\Q]" ); # expand the macros in the template: my $email_text = $macro_expander->expand_macros( $data_object, $template );To support this, a "data object" would need to exist which would need to define methods which will be used as macro names, e.g. like this: package RecordObject; sub RecipientEmail { $_->{'RecipientEmail'} } sub SenderEmail { $_->{'SenderEmail'} } sub AccountNum { $_->{'AccountNum'} } sub RecipientName { $_->{'RecipientName'} } sub PaymentAmount { $_->{'PaymentAmount'} } sub DaysPastDue { $_->{'DaysPastDue'} }Alternatively, the data object class might have AUTOLOAD defined, for example like this: package RecordObject; sub AUTOLOAD { my $self = shift; my $name = $AUTOLOAD; $name =~ s/.*:://; $self->{$name} }If this is the case, then the macro expander should be instructed not to assert that the macro names encountered are valid for the object -- since CAN might fail, even though the calls will be handled by AUTOLOAD. To do this, pass a true value for the third value to the constructor: my $macro_expander = Text::Macros->new( "\Q]", 1 );Macros can take arguments. Any strings which occur inside the macro text after the macro name will be passed as arguments to the macro method call. By default, the macro name and any arguments are all separated by newlines. You can override this behavior; see the documentation of parse_args, below.SYNOPSISuse Text::Macros; # poetic: my $macro_expander = new Text::Macros qw( {{ }} ); $text = expand_macros $macro_expander $data_object, $text; # noisy: $macro_expander = Text::Macros->new( "\Q]", 1 ); print $macro_expander->expand_macros( $data_object, $text ); Requirements: · Perl


Text::Macros Related Software