/[MARC-Fast]/trunk/lib/MARC/Fast.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/MARC/Fast.pm

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

revision 9 by dpavlin, Thu Jul 13 14:00:23 2006 UTC revision 18 by dpavlin, Mon Oct 29 22:33:35 2007 UTC
# Line 1  Line 1 
   
1  package MARC::Fast;  package MARC::Fast;
2    
3  use strict;  use strict;
4  use Carp;  use Carp;
5  use Data::Dumper;  use Data::Dumper;
# Line 7  use Data::Dumper; Line 7  use Data::Dumper;
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.04;          $VERSION     = 0.08;
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 23  MARC::Fast - Very fast implementation of Line 23  MARC::Fast - Very fast implementation of
23    
24    use MARC::Fast;    use MARC::Fast;
25    
26      my $marc = new MARC::Fast(
27            marcdb => 'unimarc.iso',
28      );
29    
30      foreach my $mfn ( 1 .. $marc->count ) {
31            print $marc->to_ascii( $mfn );
32      }
33    
34    For longer example with command line options look at L<scripts/dump_fastmarc.pl>
35    
36  =head1 DESCRIPTION  =head1 DESCRIPTION
37    
38  This is very fast alternative to C<MARC> and C<MARC::Record> modules.  This is very fast alternative to C<MARC> and C<MARC::Record> modules.
39    
40  It's is also very sutable for random access to MARC records (as opposed to  It's is also very subtable for random access to MARC records (as opposed to
41  sequential one).  sequential one).
42    
43  =head1 METHODS  =head1 METHODS
# Line 111  sub new { Line 120  sub new {
120                  print STDERR "REC ",$self->{count},": $leader\n" if ($self->{debug});                  print STDERR "REC ",$self->{count},": $leader\n" if ($self->{debug});
121    
122                  # store leader for later                  # store leader for later
123                  push @{$self->{leaders}}, $leader;                  push @{$self->{leader}}, $leader;
124    
125                  # skip to next record                  # skip to next record
126                  my $o = substr($leader,0,5);                  my $o = substr($leader,0,5);
# Line 145  Fetch record from database Line 154  Fetch record from database
154    
155    my $hash = $marc->fetch(42);    my $hash = $marc->fetch(42);
156    
157    First record number is C<1>
158    
159  =cut  =cut
160    
161  sub fetch {  sub fetch {
162          my $self = shift;          my $self = shift;
163    
164          my $rec_nr = shift || return;          my $rec_nr = shift;
165    
166          my $leader = $self->{leaders}->[$rec_nr - 1];          if ( ! $rec_nr ) {
167                    $self->{last_leader} = undef;
168                    return;
169            }
170    
171            my $leader = $self->{leader}->[$rec_nr - 1];
172            $self->{last_leader} = $leader;
173          unless ($leader) {          unless ($leader) {
174                  carp "can't find record $rec_nr";                  carp "can't find record $rec_nr";
175                  return;                  return;
# Line 234  sub fetch { Line 251  sub fetch {
251  }  }
252    
253    
254    =head2 last_leader
255    
256    Returns leader of last record L<fetch>ed
257    
258      print $marc->last_leader;
259    
260    Added in version 0.08 of this module, so if you need it use:
261    
262      use MARC::Fast 0.08;
263    
264    to be sure that it's supported.
265    
266    =cut
267    
268    sub last_leader {
269            my $self = shift;
270            return $self->{last_leader};
271    }
272    
273    
274  =head2 to_hash  =head2 to_hash
275    
276  Read record with specified MFN and convert it to hash  Read record with specified MFN and convert it to hash
# Line 313  sub to_hash { Line 350  sub to_hash {
350          return $rec;          return $rec;
351  }  }
352    
353    =head2 to_ascii
354    
355  1;    print $marc->to_ascii( 42 );
 __END__  
356    
357  =head1 BUGS  =cut
358    
359    sub to_ascii {
360            my $self = shift;
361    
362            my $mfn = shift || confess "need mfn";
363            my $row = $self->fetch($mfn) || return;
364    
365            my $out;
366    
367  =head1 SUPPORT          foreach my $f (sort keys %{$row}) {
368                    my $dump = join('', @{ $row->{$f} });
369                    $dump =~ s/\x1e$//;
370                    $dump =~ s/\x1f/\$/g;
371                    $out .= "$f\t$dump\n";
372            }
373    
374            return $out;
375    }
376    
377    1;
378    __END__
379    
380  =head1 AUTHOR  =head1 AUTHOR
381    
# Line 343  LICENSE file included with this module. Line 395  LICENSE file included with this module.
395    
396  =head1 SEE ALSO  =head1 SEE ALSO
397    
398  perl(1).  L<Biblio::Isis>, perl(1).
399    
400  =cut  =cut

Legend:
Removed from v.9  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.26