Regexp::Box - store and retrieve regexp via names
$rebox = Regexp::Box->new( name => 'name of the box' ); $rebox->register( 'category/id', 0, qr/\w/, 'description' ); $rebox->register( 'category/id2', 0, sub { '\w' x 3 }, sub { sprintf 'description of %s', $_[0] } ); unless( $_ =~ $rebox->request( 'category/id', 'regexp' ) ) { warn "Expected ", $rebox->request( 'category/id', 'desc' ); }
Store and retrieve regexp via names and serve them application wide. My favorite Regexp::Common was somehow to complicated with that particular issue.
Just give the box a name. Helps when multiple box's have to be handled.
Register a regexp. All arguments are required. The $id should contain a category path ( i.e. 'net/uri' ). It is used when later retrieved with $rebox->request. The $exact is a boolean field that defines if the regexp gets wrapped with '^$' (see $rebox->exact below). One could use closure/function-pointers as $regexp or $desc if some run-time construction would be required (Some flexible Regexp::Common regexp's require that for argument passing. Here some examples:
$id
$rebox->request
$exact
$rebox->exact
$regexp
$desc
$rebox->register( 'category/id', 0, qr//, 'description' ); $rebox->register( 'category/id', 0, sub { }, sub { 'description' } ); $rebox->register( 'std/uri', 1, sub { $Regexp::Box::RE{URI}{HTTP}{ -scheme => $_[1] || 'HTTP' } }, sub { sprintf "an uri (default: %s)", $_[1] || 'HTTP' } );
Currently 'regexp', 'desc' and 'created', 'exact' as $field_name.
$rebox->request( 'net/email', 'desc' );
Returns the desc field of the 'net/email' regexp.
desc
Returns array of $id of all registered regexps.
Wraps a regex internally into '^$'. May be overloaded if its too stupid.
Regexp::Common is heavily used and one could access it via $Regexp::Box::RE without loading it redundantly.
$Regexp::Box::RE
<& /maslib/delayed.mas, comp => '/maslib/signatures.mas:author_as_pod' &>
1 POD Error
The following errors were encountered while parsing the POD:
=back without =over
To install Regexp::Box, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Regexp::Box
CPAN shell
perl -MCPAN -e shell install Regexp::Box
For more information on module installation, please visit the detailed CPAN module installation guide.