/[webpac2]/trunk/lib/WebPAC/Normalize.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/Normalize.pm

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

revision 74 by dpavlin, Sun Nov 20 20:13:39 2005 UTC revision 252 by dpavlin, Thu Dec 15 17:01:04 2005 UTC
# Line 11  WebPAC::Normalize - data mungling for no Line 11  WebPAC::Normalize - data mungling for no
11    
12  =head1 VERSION  =head1 VERSION
13    
14  Version 0.02  Version 0.04
15    
16  =cut  =cut
17    
18  our $VERSION = '0.02';  our $VERSION = '0.04';
19    
20  =head1 SYNOPSIS  =head1 SYNOPSIS
21    
# Line 82  Create new normalisation object Line 82  Create new normalisation object
82          db => $db_obj,          db => $db_obj,
83          lookup_regex => $lookup->regex,          lookup_regex => $lookup->regex,
84          lookup => $lookup_obj,          lookup => $lookup_obj,
85            prefix => 'foobar',
86    );    );
87    
88  Parametar C<filter> defines user supplied snippets of perl code which can  Parametar C<filter> defines user supplied snippets of perl code which can
89  be use with C<filter{...}> notation.  be use with C<filter{...}> notation.
90    
91    C<prefix> is used to form filename for database record (to support multiple
92    source files which are joined in one database).
93    
94  Recommended parametar C<lookup_regex> is used to enable parsing of lookups  Recommended parametar C<lookup_regex> is used to enable parsing of lookups
95  in structures. If you pass this parametar, you must also pass C<lookup>  in structures. If you pass this parametar, you must also pass C<lookup>
96  which is C<WebPAC::Lookup> object.  which is C<WebPAC::Lookup> object.
# Line 111  sub new { Line 115  sub new {
115    
116          $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup'));          $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup'));
117    
118            $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'});
119    
120            $log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l);
121    
122          $self ? return $self : return undef;          $self ? return $self : return undef;
123  }  }
124    
# Line 124  This structures are used to produce outp Line 132  This structures are used to produce outp
132    
133   my $ds = $webpac->data_structure($rec);   my $ds = $webpac->data_structure($rec);
134    
 B<Note: historical oddity follows>  
   
 This method will also set C<< $webpac->{'currnet_filename'} >> if there is  
 C<< <filename> >> tag and C<< $webpac->{'headline'} >> if there is  
 C<< <headline> >> tag.  
   
135  =cut  =cut
136    
137  sub data_structure {  sub data_structure {
# Line 140  sub data_structure { Line 142  sub data_structure {
142          my $rec = shift;          my $rec = shift;
143          $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o);          $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o);
144    
145            $log->debug("data_structure rec = ", sub { Dumper($rec) });
146    
147            $log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'}));
148    
149            my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!");
150    
151          my $cache_file;          my $cache_file;
152    
153          if ($self->{'db'}) {          if ($self->{'db'}) {
154                  my $ds = $self->{'db'}->load_ds($rec);                  my $ds = $self->{'db'}->load_ds( id => $id, prefix => $self->{prefix} );
155                  $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) });                  $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) });
156                  return $ds if ($ds);                  return $ds if ($ds);
157                  $log->debug("cache miss, creating");                  $log->debug("cache miss, creating");
# Line 195  sub data_structure { Line 203  sub data_structure {
203                                  @v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v;                                  @v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v;
204                          }                          }
205    
                         if ($field eq 'filename') {  
                                 $self->{'current_filename'} = join('',@v);  
                                 $log->debug("filename: ",$self->{'current_filename'});  
                         } elsif ($field eq 'headline') {  
                                 $self->{'headline'} .= join('',@v);  
                                 $log->debug("headline: ",$self->{'headline'});  
                                 next; # don't return headline in data_structure!  
                         }  
   
206                          # delimiter will join repeatable fields                          # delimiter will join repeatable fields
207                          if ($tag->{'delimiter'}) {                          if ($tag->{'delimiter'}) {
208                                  @v = ( join($tag->{'delimiter'}, @v) );                                  @v = ( join($tag->{'delimiter'}, @v) );
# Line 216  sub data_structure { Line 215  sub data_structure {
215    
216                          foreach my $type (@types) {                          foreach my $type (@types) {
217                                  # append to previous line?                                  # append to previous line?
218                                  $log->debug("type: $type ",sub { join(" ",@v) }, $row->{'append'} || 'no append');                                  $log->debug("type: $type ",sub { join(" ",@v) }, " ", $row->{'append'} || 'no append');
219                                  if ($tag->{'append'}) {                                  if ($tag->{'append'}) {
220    
221                                          # I will delimit appended part with                                          # I will delimit appended part with
# Line 257  sub data_structure { Line 256  sub data_structure {
256    
257          }          }
258    
         $log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'});  
   
259          $self->{'db'}->save_ds(          $self->{'db'}->save_ds(
260                    id => $id,
261                  ds => $ds,                  ds => $ds,
262                  current_filename => $self->{'current_filename'},                  prefix => $self->{prefix},
                 headline => $self->{'headline'},  
263          ) if ($self->{'db'});          ) if ($self->{'db'});
264    
265          $log->debug("ds: ", sub { Dumper($ds) });          $log->debug("ds: ", sub { Dumper($ds) });
# Line 466  sub fill_in { Line 463  sub fill_in {
463                  # do we have lookups?                  # do we have lookups?
464                  if ($self->{'lookup'}) {                  if ($self->{'lookup'}) {
465                          if ($self->{'lookup'}->can('lookup')) {                          if ($self->{'lookup'}->can('lookup')) {
466                                  return $self->{'lookup'}->lookup($format);                                  my @lookup = $self->{lookup}->lookup($format);
467                                    $log->debug('lookup $format', join(", ", @lookup));
468                                    return @lookup;
469                          } else {                          } else {
470                                  $log->warn("Have lookup object but can't invoke lookup method");                                  $log->warn("Have lookup object but can't invoke lookup method");
471                          }                          }
# Line 680  under the same terms as Perl itself. Line 679  under the same terms as Perl itself.
679    
680  =cut  =cut
681    
682  1; # End of WebPAC::DB  1; # End of WebPAC::Normalize

Legend:
Removed from v.74  
changed lines
  Added in v.252

  ViewVC Help
Powered by ViewVC 1.1.26