supprot \x42 HEX numbers in recode
[webpac2] / lib / WebPAC / Input / Gutenberg.pm
index e9cd1aa..a069da3 100644 (file)
@@ -4,7 +4,8 @@ use warnings;
 use strict;
 
 use WebPAC::Input;
-use base qw/WebPAC::Common/;
+use WebPAC::Input::Helper;
+use base qw/WebPAC::Common WebPAC::Input::Helper/;
 use XML::LibXML;
 use Data::Dump qw/dump/;
 use Encode qw/encode_utf8/;
@@ -15,11 +16,11 @@ WebPAC::Input::Gutenberg - support for RDF catalog data from Project Gutenberg
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 
 =head1 SYNOPSIS
@@ -97,10 +98,9 @@ sub new {
 
                # this is a book description node
                my $etext_no = $booknode->getAttribute ('ID');
-               $etext_no =~ s/^etext//;
+               $etext_no =~ s/^etext// if $etext_no;
 
                my $row = {
-                       '000' => [ $mfn ],
                        '001' => [ $etext_no ],
                };
 
@@ -111,7 +111,7 @@ sub new {
                                push @{ $row->{$f} }, '^' . $sf . encode_utf8( $v->textContent );
                        }
 
-                       $log->debug("using $xpath to fill $f^$sf ==> ", dump( $row->{$f} ));
+                       $log->debug("using $xpath to fill $f^$sf ==> ", dump( $row->{$f} )) if (defined( $row->{$f} ));
                }
 
                $self->{_rows}->{ $mfn } = $row;
@@ -166,80 +166,6 @@ sub size {
        return $self->{size};
 }
 
-=head2 _to_hash
-
-Return hash from row. Taken from L<Biblio::Isis>
-
-  my $rec = $ll_db->_to_hash(
-       mfn => $mfn;
-       $row
-  );
-
-=cut
-
-sub _to_hash {
-       my $self = shift;
-
-       my $arg = {@_};
-
-       my $log = $self->_get_logger();
-
-       my $hash_filter = $arg->{hash_filter};
-       my $mfn = $arg->{mfn} || $log->logconfess("need mfn in arguments");
-       my $row = $arg->{row} || $log->logconfess("need row in arguments");
-
-       # init record to include MFN as field 000
-       my $rec = { '000' => [ $mfn ] };
-
-       foreach my $f_nr (keys %{$row}) {
-               foreach my $l (@{$row->{$f_nr}}) {
-
-                       # filter output
-                       $l = $hash_filter->($l, $f_nr) if ($hash_filter);
-                       next unless defined($l);
-
-                       my $val;
-                       my $r_sf;       # repeatable subfields in this record
-
-                       # has subfields?
-                       if ($l =~ m/\^/) {
-                               foreach my $t (split(/\^/,$l)) {
-                                       next if (! $t);
-                                       my ($sf,$v) = (substr($t,0,1), substr($t,1));
-                                       next unless (defined($v) && $v ne '');
-
-                                       if (ref( $val->{$sf} ) eq 'ARRAY') {
-
-                                               push @{ $val->{$sf} }, $v;
-
-                                               # record repeatable subfield it it's offset
-                                               push @{ $val->{subfields} }, ( $sf, $#{ $val->{$sf} } );
-                                               $r_sf->{$sf}++;
-
-                                       } elsif (defined( $val->{$sf} )) {
-
-                                               # convert scalar field to array
-                                               $val->{$sf} = [ $val->{$sf}, $v ];
-
-                                               push @{ $val->{subfields} }, ( $sf, 1 );
-                                               $r_sf->{$sf}++;
-
-                                       } else {
-                                               $val->{$sf} = $v;
-                                               push @{ $val->{subfields} }, ( $sf, 0 );
-                                       }
-                               }
-                       } else {
-                               $val = $l;
-                       }
-
-                       push @{$rec->{$f_nr}}, $val;
-               }
-       }
-
-       return $rec;
-}
-
 =head1 AUTHOR
 
 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>