2 |
|
|
3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
use base 'WebPAC::Common'; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
|
|
8 |
=head1 NAME |
=head1 NAME |
79 |
return length($_); |
return length($_); |
80 |
}, ... |
}, ... |
81 |
}, |
}, |
82 |
db => $webpac_db_obj, |
db => $db_obj, |
83 |
lookup_regex => $lookup->regex, |
lookup_regex => $lookup->regex, |
84 |
|
lookup => $lookup_obj, |
85 |
); |
); |
86 |
|
|
87 |
Parametar C<filter> defines user supplied snippets of perl code which can |
Parametar C<filter> defines user supplied snippets of perl code which can |
88 |
be use with C<filter{...}> notation. |
be use with C<filter{...}> notation. |
89 |
|
|
90 |
Recommended parametar C<lookup_regex> is used to enable parsing of lookups |
Recommended parametar C<lookup_regex> is used to enable parsing of lookups |
91 |
in structures. |
in structures. If you pass this parametar, you must also pass C<lookup> |
92 |
|
which is C<WebPAC::Lookup> object. |
93 |
|
|
94 |
=cut |
=cut |
95 |
|
|
98 |
my $self = {@_}; |
my $self = {@_}; |
99 |
bless($self, $class); |
bless($self, $class); |
100 |
|
|
101 |
|
my $r = $self->{'lookup_regex'} ? 1 : 0; |
102 |
|
my $l = $self->{'lookup'} ? 1 : 0; |
103 |
|
|
104 |
|
my $log = $self->_get_logger(); |
105 |
|
|
106 |
|
# those two must be in pair |
107 |
|
if ( ($r & $l) != ($r || $l) ) { |
108 |
|
my $log = $self->_get_logger(); |
109 |
|
$log->logdie("lookup_regex and lookup must be in pair"); |
110 |
|
} |
111 |
|
|
112 |
|
$log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); |
113 |
|
|
114 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
115 |
} |
} |
116 |
|
|
143 |
my $cache_file; |
my $cache_file; |
144 |
|
|
145 |
if ($self->{'db'}) { |
if ($self->{'db'}) { |
146 |
my @ds = $self->{'db'}->get_ds($rec); |
my @ds = $self->{'db'}->load_ds($rec); |
147 |
return @ds if (@ds); |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) }); |
148 |
|
return @ds if ($#ds > 0); |
149 |
|
$log->debug("cache miss, creating"); |
150 |
} |
} |
151 |
|
|
152 |
undef $self->{'currnet_filename'}; |
undef $self->{'currnet_filename'}; |
254 |
|
|
255 |
} |
} |
256 |
|
|
257 |
$self->{'db'}->put_gs( |
$self->{'db'}->save_ds( |
258 |
ds => \@ds, |
ds => \@ds, |
259 |
current_filename => $self->{'current_filename'}, |
current_filename => $self->{'current_filename'}, |
260 |
headline => $self->{'headline'}, |
headline => $self->{'headline'}, |
261 |
) if ($self->{'db'}); |
) if ($self->{'db'}); |
262 |
|
|
263 |
|
$log->debug("ds: ", sub { Dumper(@ds) }); |
264 |
|
|
265 |
return @ds; |
return @ds; |
266 |
|
|
267 |
} |
} |
458 |
} |
} |
459 |
# do we have lookups? |
# do we have lookups? |
460 |
if ($self->{'lookup'}) { |
if ($self->{'lookup'}) { |
461 |
return $self->lookup($format); |
if ($self->{'lookup'}->can('lookup')) { |
462 |
|
return $self->{'lookup'}->lookup($format); |
463 |
|
} else { |
464 |
|
$log->warn("Have lookup object but can't invoke lookup method"); |
465 |
|
} |
466 |
} else { |
} else { |
467 |
return $format; |
return $format; |
468 |
} |
} |
588 |
$log->debug("using format $name [$format] on $data to produce: $out"); |
$log->debug("using format $name [$format] on $data to produce: $out"); |
589 |
|
|
590 |
if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { |
if ($self->{'lookup_regex'} && $out =~ $self->{'lookup_regex'}) { |
591 |
return $self->lookup($out); |
return $self->{'lookup'}->lookup($out); |
592 |
} else { |
} else { |
593 |
return $out; |
return $out; |
594 |
} |
} |