String::MatchInterpolate

String::MatchInterpolate can perform named regexp capture and variable interpolation from the same template.
Download

String::MatchInterpolate Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Paul Evans
  • Publisher web site:
  • http://search.cpan.org/~pevans/String-Expand-0.03/lib/String/Expand.pm

String::MatchInterpolate Tags


String::MatchInterpolate Description

String::MatchInterpolate can perform named regexp capture and variable interpolation from the same template. String::MatchInterpolate can perform named regexp capture and variable interpolation from the same template.SYNOPSIS use String::MatchInterpolate; my $smi = String::MatchInterpolate->new( 'My name is ${NAME/w+/}' ); my $vars = $smi->match( "My name is Bob" ); my $name = $vars->{NAME}; print $smi->interpolate( { NAME => "Jim" } ) . "n";This module provides an object class which represents a string matching and interpolation pattern. It contains named-variable placeholders which include a regexp pattern to match them on. An instance of this class represents a single pattern, which can be matched against or interpolated into.Objects in this class are not modified once constructed; they do not store any runtime state other than data derived arguments passed to the constructor.Template FormatThe template consists of a string with named variable placeholders embedded in it. It looks similar to a perl or shell string with interpolation:A string here with ${NAME/pattern/} interpolationsThe embedded variable is delmited by perl-style ${ } braces, and contains a name and a pattern. The pattern is a normal perl regexp fragment that will be used by the match() method. This regexp should not contain any capture brackets ( ) as these will confuse the parsing logic.Outside of the embedded variables, the string is interpreted literally; i.e. not as a regexp pattern. A backslash may be used to escape the following character, allowing literal backslashes or dollar signs to be used.The intended use for this object class is that the template strings would come from a configuration file, or some other source of "trusted" input. In the current implementation, there is nothing to stop a carefully-crafted string from containing arbitrary perl code, which would be executed every time the match() or interpolate() methods are called. (See "SECURITY" section). This fact may be changed in a later version.Requirements:· Perl Requirements: · Perl


String::MatchInterpolate Related Software