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 ();
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";
}
=back
-It will also set C<$isis-E<gt>{'maxmfn'}> which is maximum MFN stored in database.
-
=cut
sub new {
read($self->{'fileMST'}, $buff, 4);
$self->{'NXTMFN'}=unpack("l",$buff) || carp "NXTNFN is zero";
- # save maximum MFN
- $self->{'maxmfn'} = $self->{'NXTMFN'} - 1;
-
$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.
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);
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
isa_ok ($isis, 'IsisDB');
- cmp_ok($isis->{maxmfn}, '==', 5, "maxmfn set to 5");
+ cmp_ok($isis->count, '==', 5, "count is 5");
# test .CNT 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");
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");
}