/[Biblio-Isis]/trunk/lib/Biblio/Isis.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/Biblio/Isis.pm

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

revision 56 by dpavlin, Sat Jul 8 16:03:52 2006 UTC revision 57 by dpavlin, Sun Jul 9 12:12:57 2006 UTC
# Line 7  use File::Glob qw(:globally :nocase); Line 7  use File::Glob qw(:globally :nocase);
7  BEGIN {  BEGIN {
8          use Exporter ();          use Exporter ();
9          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);          use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
10          $VERSION     = 0.20;          $VERSION     = 0.21;
11          @ISA         = qw (Exporter);          @ISA         = qw (Exporter);
12          #Give a hoot don't pollute, do not export more than needed by default          #Give a hoot don't pollute, do not export more than needed by default
13          @EXPORT      = qw ();          @EXPORT      = qw ();
# Line 88  Open ISIS database Line 88  Open ISIS database
88                  $v =~ s#foo#bar#g;                  $v =~ s#foo#bar#g;
89          },          },
90          debug => 1,          debug => 1,
91            join_subfields_with => ' ; ',
92   );   );
93    
94  Options are described below:  Options are described below:
# Line 119  Filter code ref which will be used befor Line 120  Filter code ref which will be used befor
120    
121  Dump a B<lot> of debugging output even at level 1. For even more increase level.  Dump a B<lot> of debugging output even at level 1. For even more increase level.
122    
123    =item join_subfields_with
124    
125    Define delimiter which will be used to join repeatable subfields. This
126    option is included to support lagacy application written against version
127    older than 0.21 of this module. By default, it disabled. See L</to_hash>.
128    
129  =back  =back
130    
131  =cut  =cut
# Line 489  following structure: Line 496  following structure:
496          'a' => [ 'foo', 'bar', 'baz' ],          'a' => [ 'foo', 'bar', 'baz' ],
497    }]    }]
498    
499    Or in more complex example of
500    
501      902   ^aa1^aa2^aa3^bb1^aa4^bb2^cc1^aa5
502    
503    it will create
504    
505      902   => [
506            { a => ["a1", "a2", "a3", "a4", "a5"], b => ["b1", "b2"], c => "c1" },
507      ],
508    
509    This behaviour can be changed using C<join_subfields_with> option to L</new>,
510    in which case C<to_hash> will always create single value for each subfield.
511    This will change result to:
512    
513    
514    
515  This method will also create additional field C<000> with MFN.  This method will also create additional field C<000> with MFN.
516    
517  There is also more elaborative way to call C<to_hash> like this:  There is also more elaborative way to call C<to_hash> like this:
518    
519    my $hash = $isis->to_hash({    my $hash = $isis->to_hash({
520          mfn => 42,          mfn => 42,
521          include_empty_subfields => 1,          include_subfields => 1,
522    });    });
523    
524    Each option controll creation of hash:
525    
526    =over 4
527    
528    =item mfn
529    
530    Specify MFN number of record
531    
532    =item include_subfields
533    
534    This option will create additional key in hash called C<subfields> which will
535    have original record subfield order and index to that subfield like this:
536    
537      902   => [ {
538            a => ["a1", "a2", "a3", "a4", "a5"],
539            b => ["b1", "b2"],
540            c => "c1",
541            subfields => ["a", 0, "a", 1, "a", 2, "b", 0, "a", 3, "b", 1, "c", 0, "a", 4],
542      } ],
543    
544    =item join_subfields_with
545    
546    Define delimiter which will be used to join repeatable subfields. You can
547    specify option here instead in L</new> if you want to have per-record controll.
548    
549    =back
550    
551  =cut  =cut
552    
553  sub to_hash {  sub to_hash {
# Line 517  sub to_hash { Line 567  sub to_hash {
567    
568          my $row = $self->fetch($mfn) || return;          my $row = $self->fetch($mfn) || return;
569    
570          foreach my $k (keys %{$row}) {          my $j_rs = $arg->{join_repeatable_subfields};
571                  foreach my $l (@{$row->{$k}}) {          $j_rs = $self->{join_repeatable_subfields} unless(defined($j_rs));
572            my $i_sf = $arg->{include_subfields};
573    
574            foreach my $f_nr (keys %{$row}) {
575                    foreach my $l (@{$row->{$f_nr}}) {
576    
577                          # filter output                          # filter output
578                          if ($self->{'hash_filter'}) {                          if ($self->{'hash_filter'}) {
# Line 527  sub to_hash { Line 581  sub to_hash {
581                          }                          }
582    
583                          my $val;                          my $val;
584                            my $r_sf;       # repeatable subfields in this record
585    
586                          # has identifiers?                          # has identifiers?
587                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\^/\^/);                          ($val->{'i1'},$val->{'i2'}) = ($1,$2) if ($l =~ s/^([01 #])([01 #])\^/\^/);
# Line 536  sub to_hash { Line 591  sub to_hash {
591                                  foreach my $t (split(/\^/,$l)) {                                  foreach my $t (split(/\^/,$l)) {
592                                          next if (! $t);                                          next if (! $t);
593                                          my ($sf,$v) = (substr($t,0,1), substr($t,1));                                          my ($sf,$v) = (substr($t,0,1), substr($t,1));
594                                          # FIXME make this option !                                          # XXX this might be option, but why?
595                                          next unless ($v);                                          next unless ($v);
596  #                                       warn "### $k^$sf:$v",$/ if ($self->{debug} > 1);  #                                       warn "### $f_nr^$sf:$v",$/ if ($self->{debug} > 1);
597    
                                         # FIXME array return optional, by default unroll to ' ; '  
598                                          if (ref( $val->{$sf} ) eq 'ARRAY') {                                          if (ref( $val->{$sf} ) eq 'ARRAY') {
599    
600                                                  push @{ $val->{$sf} }, $v;                                                  push @{ $val->{$sf} }, $v;
601    
602                                                    # record repeatable subfield it it's offset
603                                                    push @{ $val->{subfields} }, ( $sf, $#{ $val->{$sf} } ) if (! $j_rs && $i_sf);
604                                                    $r_sf->{$sf}++;
605    
606                                          } elsif (defined( $val->{$sf} )) {                                          } elsif (defined( $val->{$sf} )) {
607    
608                                                  # convert scalar field to array                                                  # convert scalar field to array
609                                                  $val->{$sf} = [ $val->{$sf}, $v ];                                                  $val->{$sf} = [ $val->{$sf}, $v ];
610    
611                                                    push @{ $val->{subfields} }, ( $sf, 1 ) if (! $j_rs && $i_sf);
612                                                    $r_sf->{$sf}++;
613    
614                                          } else {                                          } else {
615                                                  $val->{$sf} = $v;                                                  $val->{$sf} = $v;
616                                                    push @{ $val->{subfields} }, ( $sf, 0 ) if ($i_sf);
617                                          }                                          }
618                                  }                                  }
619                          } else {                          } else {
620                                  $val = $l;                                  $val = $l;
621                          }                          }
622    
623                          push @{$rec->{$k}}, $val;                          if ($j_rs) {
624                                    map {
625                                            $val->{$_} = join($j_rs, @{ $val->{$_} });
626                                    } keys %$r_sf
627                            }
628    
629                            push @{$rec->{$f_nr}}, $val;
630                  }                  }
631          }          }
632    
# Line 670  know any details about it's version. Line 741  know any details about it's version.
741    
742  =head1 VERSIONS  =head1 VERSIONS
743    
744  You can find version dependencies documented here  As this is young module, new features are added in subsequent version. It's
745    a good idea to specify version when using this module like this:
746    
747      use Biblio::Isis 0.21
748    
749    Below is list of changes in specific version of module (so you can target
750    older versions if you really have to):
751    
752  =over 8  =over 8
753    
754    =item 0.21
755    
756    Added C<join_subfields_with> to L</new> and L</to_hash>.
757    
758    Added C<include_subfields> to L</to_hash>.
759    
760  =item 0.20  =item 0.20
761    
762  Added C<< $isis->mfn >>, support for repeatable subfields and  Added C<< $isis->mfn >>, support for repeatable subfields and

Legend:
Removed from v.56  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26