The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Regexp::Box - store and retrieve regexp via names

SYNOPSIS

 $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' );
 }

DESCRIPTION

Store and retrieve regexp via names and serve them application wide. My favorite Regexp::Common was somehow to complicated with that particular issue.

METHODS

$rebox = Regexp::Box->new( name => 'name of the box' )

Just give the box a name. Helps when multiple box's have to be handled.

$rebox->register( $id, $exact, $regexp, $desc )

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:

 $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' } 
 );

$field = $rebox->request( $id, $field_name )

Currently 'regexp', 'desc' and 'created', 'exact' as $field_name.

 $rebox->request( 'net/email', 'desc' );

Returns the desc field of the 'net/email' regexp.

@ids = $rebox->request();

Returns array of $id of all registered regexps.

$rebox->exact

Wraps a regex internally into '^$'. May be overloaded if its too stupid.

$Regexp::Box::RE

Regexp::Common is heavily used and one could access it via $Regexp::Box::RE without loading it redundantly.

<& /maslib/delayed.mas, comp => '/maslib/signatures.mas:author_as_pod' &>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 309:

=back without =over