use File::Slurp;
use Data::Dumper;
-my $LOOKUP_REGEX = 'lookup{[^\{\}]+}';
-my $LOOKUP_REGEX_SAVE = 'lookup{([^\{\}]+)}';
-
=head1 NAME
WebPAC::Lookup - simple normalisation plugin to produce lookup
my $lookup = new WebPAC::Lookup(
lookup_file => '/path/to/conf/lookup/lookup.pm',
+ is_lookup_regex => 'lookup{[^\{\}]+}';
+ save_lookup_regex => 'lookup{([^\{\}]+)}';
);
=cut
$log->logconfess("lookup config file isn't ARRAY", sub { Dumper( $self->{'lookup_def'} ) }) if ($self->{'lookup_def'} !~ /ARRAY/o);
+ $self->{'is_lookup_regex'} ||= 'lookup{[^\{\}]+}';
+ $self->{'save_lookup_regex'} ||= 'lookup{([^\{\}]+)}';
+
+
+ $self->{'LOOKUP_REGEX'} = qr/$self->{'is_lookup_regex'}/;
+ $self->{'LOOKUP_REGEX_SAVE'} = qr/$self->{'save_lookup_regex'}/;
+
+ $log->debug("regexps: ", $self->{'LOOKUP_REGEX'}, " ", $self->{'LOOKUP_REGEX_SAVE'});
+
$self ? return $self : return undef;
}
my $tmp = shift || $log->logconfess("need format");
- if ($tmp =~ /$LOOKUP_REGEX/o) {
+ if ($tmp =~ $self->{'LOOKUP_REGEX'}) {
my @in = ( $tmp );
$log->debug("lookup for: ",$tmp);
my @out;
while (my $f = shift @in) {
- if ($f =~ /$LOOKUP_REGEX_SAVE/o) {
+ if ($f =~ $self->{'LOOKUP_REGEX_SAVE'}) {
my $k = $1;
if ($self->{'lookup'}->{$k}) {
foreach my $nv (@{$self->{'lookup'}->{$k}}) {
}
}
+=head2 regex
+
+Returns precompiled regex for lookup format.
+
+ if ($foo =~ $lookup->reges) { ... }
+
+=cut
+
+sub regex {
+ my $self = shift;
+
+ return $self->{'LOOKUP_REGEX'};
+}
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>