new api version
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 5 Jan 2005 15:46:26 +0000 (15:46 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 5 Jan 2005 15:46:26 +0000 (15:46 +0000)
- added count method (instead of calling maxmfn directly in object)
- added POD coverage test
- moved unpack_cnt to be separate method and document it

git-svn-id: file:///home/dpavlin/svn/Biblio-Isis/trunk@32 4670fa4d-42ec-0310-ab5b-a66af6943492

IsisDB.pm
MANIFEST
scripts/bench.pl
scripts/dump_isisdb.pl
t/002_isis.t
t/998_pod-coverage.t [new file with mode: 0755]

index 22d56d0..75d4e5f 100644 (file)
--- a/IsisDB.pm
+++ b/IsisDB.pm
@@ -9,7 +9,7 @@ use Data::Dumper;
 BEGIN {
        use Exporter ();
        use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-       $VERSION     = 0.08;
+       $VERSION     = 0.09;
        @ISA         = qw (Exporter);
        #Give a hoot don't pollute, do not export more than needed by default
        @EXPORT      = qw ();
@@ -30,7 +30,7 @@ IsisDB - Read CDS/ISIS, WinISIS and IsisMarc database
        isisdb => './cds/cds',
   );
 
-  for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) {
+  for(my $mfn = 1; $mfn <= $isis->count; $mfn++) {
        print $isis->to_ascii($mfn),"\n";
   }
 
@@ -123,8 +123,6 @@ Dump a B<lot> of debugging output.
 
 =back
 
-It will also set C<$isis-E<gt>{'maxmfn'}> which is maximum MFN stored in database.
-
 =cut
 
 sub new {
@@ -199,9 +197,6 @@ sub new {
        read($self->{'fileMST'}, $buff, 4);
        $self->{'NXTMFN'}=unpack("l",$buff) || carp "NXTNFN is zero";
 
-       # save maximum MFN
-       $self->{'maxmfn'} = $self->{'NXTMFN'} - 1;
-
 
 
 
@@ -213,6 +208,19 @@ sub new {
        $self ? return $self : return undef;
 }
 
+=head2 count
+
+Return number of records in database
+
+  print $isis->count;
+
+=cut
+
+sub count {
+       my $self = shift;
+       return $self->{'NXTMFN'} - 1;
+}
+
 =head2 read_cnt
 
 Read content of C<.CNT> file and return hash containing it.
@@ -234,36 +242,6 @@ sub read_cnt  {
    
        open(fileCNT, $self->{cnt_file}) || croak "can't read '$self->{cnt_file}': $!";
 
-       # There is two 26 Bytes fixed lenght records
-
-       #  0: IDTYPE    BTree type                              16
-       #  2: ORDN      Nodes Order                             16
-       #  4: ORDF      Leafs Order                             16
-       #  6: N         Number of Memory buffers for nodes      16
-       #  8: K         Number of buffers for first level index 16
-       # 10: LIV       Current number of Index Levels          16
-       # 12: POSRX*    Pointer to Root Record in N0x           32
-       # 16: NMAXPOS*  Next Available position in N0x          32
-       # 20: FMAXPOS*  Next available position in L0x          32
-       # 24: ABNORMAL  Formal BTree normality indicator        16
-       # length: 26 bytes
-
-       sub unpack_cnt {
-               my $self = shift;
-
-               my @flds = qw(ORDN ORDF N K LIV POSRX NMAXPOS FMAXPOS ABNORMAL);
-
-               my $buff = shift || return;
-               my @arr = unpack("ssssssllls", $buff);
-
-               print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});
-
-               my $IDTYPE = shift @arr;
-               foreach (@flds) {
-                       $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr);
-               }
-       }
-
        my $buff;
 
        read(fileCNT, $buff, 26);
@@ -277,6 +255,45 @@ sub read_cnt  {
        return $self->{cnt};
 }
 
+=head2 unpack_cnt
+
+Unpack one of two 26 bytes fixed length record in C<.CNT> file.
+
+Here is definition of record:
+
+ off key       description                             size
+  0: IDTYPE    BTree type                              s
+  2: ORDN      Nodes Order                             s
+  4: ORDF      Leafs Order                             s
+  6: N         Number of Memory buffers for nodes      s
+  8: K         Number of buffers for first level index s
+ 10: LIV       Current number of Index Levels          s
+ 12: POSRX     Pointer to Root Record in N0x           l
+ 16: NMAXPOS   Next Available position in N0x          l
+ 20: FMAXPOS   Next available position in L0x          l
+ 24: ABNORMAL  Formal BTree normality indicator        s
+ length: 26 bytes
+
+This will fill C<$self> object under C<cnt> with hash. It's used by C<read_cnt>.
+
+=cut
+
+sub unpack_cnt {
+       my $self = shift;
+
+       my @flds = qw(ORDN ORDF N K LIV POSRX NMAXPOS FMAXPOS ABNORMAL);
+
+       my $buff = shift || return;
+       my @arr = unpack("ssssssllls", $buff);
+
+       print STDERR "unpack_cnt: ",join(" ",@arr),"\n" if ($self->{'debug'});
+
+       my $IDTYPE = shift @arr;
+       foreach (@flds) {
+               $self->{cnt}->{$IDTYPE}->{$_} = abs(shift @arr);
+       }
+}
+
 =head2 fetch
 
 Read record with selected MFN
index fa3d0c2..39a3af9 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,6 +6,7 @@ Makefile.PL
 IsisDB.pm
 t/001_load.t
 t/002_isis.t
+t/998_pod-coverage.t
 t/999_pod.t
 scripts/dump_isisdb.pl
 scripts/dump_openisis.pl
@@ -30,3 +31,4 @@ data/winisis/BIBL.N01
 data/winisis/BIBL.N02
 data/winisis/BIBL.XRF
 data/winisis/BIBL.FDT
+META.yml                                 Module meta-data (added by MakeMaker)
index ae79854..4fd3cb2 100755 (executable)
@@ -25,7 +25,7 @@ my $isis_filter = IsisDB->new (
        }
 );
 
-my $rows = $isis->{'maxmfn'};
+my $rows = $isis->count;
 
 my $db = OpenIsis::open( $isisdb );
 
index adbc250..0a5fb51 100755 (executable)
@@ -16,9 +16,9 @@ my $isis = IsisDB->new (
 #      read_fdt => 1,
 );
 
-print "rows: ",$isis->{'maxmfn'},"\n\n";
+print "rows: ",$isis->count,"\n\n";
 
-for(my $mfn = 1; $mfn <= $isis->{'maxmfn'}; $mfn++) {
+for(my $mfn = 1; $mfn <= $isis->count; $mfn++) {
        print STDERR Dumper($isis->to_hash($mfn)),"\n" if ($debug);
        print $isis->to_ascii($mfn),"\n";
 
index 3b93a0a..6594491 100755 (executable)
@@ -17,7 +17,7 @@ sub test_data {
 
        isa_ok ($isis, 'IsisDB');
 
-       cmp_ok($isis->{maxmfn}, '==', 5, "maxmfn set to 5");
+       cmp_ok($isis->count, '==', 5, "count is 5");
 
        # test .CNT data
 
@@ -92,7 +92,7 @@ sub test_data {
                '200' => [ '1#^aPsychology^fCamille B. Wortman, Elizabeth F. Loftus, Mary E. Marshal' ],
        } ];
                
-       foreach my $mfn (1 .. $isis->{'maxmfn'}) {
+       foreach my $mfn (1 .. $isis->count) {
                my $rec;
                ok($rec = $isis->fetch($mfn), "fetch $mfn");
 
@@ -113,7 +113,7 @@ sub test_data {
 
                skip "no Digest::MD5 module", 5 if ($@);
 
-               foreach my $mfn (1 .. $isis->{'maxmfn'}) {
+               foreach my $mfn (1 .. $isis->count) {
                        my $md5 = md5_hex($isis->to_ascii($mfn));
                        cmp_ok($md5, 'eq', $args->{md5_ascii}[$mfn - 1], "md5 $mfn");
                }
diff --git a/t/998_pod-coverage.t b/t/998_pod-coverage.t
new file mode 100755 (executable)
index 0000000..8f0fc65
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/perl -w
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.00";
+plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
+all_pod_coverage_ok();
+