/[webpac2]/trunk/lib/WebPAC/Parser.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Parser.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 724 by dpavlin, Fri Sep 29 18:55:31 2006 UTC revision 737 by dpavlin, Thu Oct 5 14:38:45 2006 UTC
# Line 13  use base qw/WebPAC::Common/; Line 13  use base qw/WebPAC::Common/;
13    
14  =head1 NAME  =head1 NAME
15    
16  WebPAC::Parser - parse perl normalization configuration files and mungle it  WebPAC::Parser - parse perl normalization configuration files (rules) and mungle it
17    
18  =head1 VERSION  =head1 VERSION
19    
20  Version 0.06  Version 0.07
21    
22  =cut  =cut
23    
24  our $VERSION = '0.06';  our $VERSION = '0.07';
25    
26  =head1 SYNOPSIS  =head1 SYNOPSIS
27    
28  This module will parse L<WebPAC::Normalize/lookup> directives and generate source  This module will parse L<WebPAC::Normalize/lookup> directives and generate source
29  to produce lookups and normalization.  to produce lookups and normalization. It will also parse other parts of
30    source to produce some of DWIM (I<Do What I Mean>) magic
31    (like producing MARC oputput using L<WebPAC::Output::MARC> if there are C<marc_*>
32    rules in normalisation).
33    
34  It's written using L<PPI>, pure-perl parser for perl and heavily influenced by  It's written using L<PPI>, pure-perl parser for perl and heavily influenced by
35  reading about LISP. It might be a bit over-the board, but at least it removed  reading about LISP. It might be a bit over-the board, but at least it removed
# Line 165  sub normalize_rules { Line 168  sub normalize_rules {
168          return $self->{_normalize_source}->{ _q($database) }->{ _q($input) };          return $self->{_normalize_source}->{ _q($database) }->{ _q($input) };
169  }  }
170    
171    
172    =head2 generate_marc
173    
174      my $do_marc = $parser->generate_marc($database, $input);
175    
176    This function will return hash containing count of all found C<marc_*> directives.
177    
178    =cut
179    
180    sub generate_marc {
181            my $self = shift;
182            my ($database,$input) = @_;
183            $input = _input_name($input);
184            return unless (
185                    defined( $self->{_generate_marc}->{ _q($database) } ) &&
186                    defined( $self->{_generate_marc}->{ _q($database) }->{ _q($input) } )
187            );
188            return $self->{_generate_marc}->{ _q($database) }->{ _q($input) };
189    }
190    
191    
192  =head1 PRIVATE  =head1 PRIVATE
193    
194  =head2 _read_sources  =head2 _read_sources
# Line 182  sub _read_sources { Line 206  sub _read_sources {
206    
207          my $nr = 0;          my $nr = 0;
208    
209          my @lookups;          my @sources;
210    
211          $self->{config}->iterate_inputs( sub {          $self->{config}->iterate_inputs( sub {
212                  my ($input, $database) = @_;                  my ($input, $database) = @_;
# Line 205  sub _read_sources { Line 229  sub _read_sources {
229    
230                          $self->{valid_inputs}->{$database}->{$input_name}++;                          $self->{valid_inputs}->{$database}->{$input_name}++;
231    
232                          push @lookups, sub {                          push @sources, sub {
233                                  $self->_parse_lookups( $database, $input_name, $full, $s );                                  $self->_parse_source( $database, $input_name, $full, $s );
234                          };                          };
235    
236                          $nr++;                          $nr++;
# Line 215  sub _read_sources { Line 239  sub _read_sources {
239    
240          $log->debug("found $nr source files");          $log->debug("found $nr source files");
241    
242          # parse all lookups          # parse all sources
243          $_->() foreach (@lookups);          $_->() foreach (@sources);
244    
245          return $nr;          return $nr;
246  }  }
247    
248  =head2 _parse_lookups  =head2 _parse_source
249    
250    $parser->_parse_lookups($database,$input,$path,$source);    $parser->_parse_source($database,$input,$path,$source);
251    
252  Called for each normalize source (rules) in each input by L</_read_sources>  Called for each normalize source (rules) in each input by L</_read_sources>
253    
# Line 231  It will report invalid databases and inp Line 255  It will report invalid databases and inp
255    
256  =cut  =cut
257    
258  sub _parse_lookups {  sub _parse_source {
259          my $self = shift;          my $self = shift;
260          my ($database, $input, $path, $source) = @_;          my ($database, $input, $path, $source) = @_;
261    
# Line 362  sub _parse_lookups { Line 386  sub _parse_lookups {
386    
387          $log->error("Parser errors:\n", join("\n",@{ $self->{_lookup_errors} }) ) if ($self->{_lookup_errors});          $log->error("Parser errors:\n", join("\n",@{ $self->{_lookup_errors} }) ) if ($self->{_lookup_errors});
388    
389            $Document->find( sub {
390                            my ($Document,$Element) = @_;
391    
392                            $Element->isa('PPI::Token::Word') or return '';
393                            $Element->content =~ m/^marc/ or return '';
394    
395                            $log->debug("found marc output generation for $database/$input");
396                            $self->{_generate_marc}->{ $database }->{ $input }->{ $Element->content }++;
397            });
398    
399          return 1;          return 1;
400  }  }
401    

Legend:
Removed from v.724  
changed lines
  Added in v.737

  ViewVC Help
Powered by ViewVC 1.1.26