| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tie::MAB2::RecnoViaId; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1205
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
|
6
|
1
|
|
|
1
|
|
5
|
use Tie::Hash; |
|
|
1
|
|
|
|
|
474
|
|
|
|
1
|
|
|
|
|
43
|
|
|
7
|
1
|
|
|
1
|
|
31
|
our @ISA = qw(Tie::StdHash); |
|
8
|
|
|
|
|
|
|
} |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
340
|
use BerkeleyDB qw( DB_RDONLY DB_CREATE DB_FAST_STAT ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
warn sprintf "WARNING: Recommended Berkeley DB version is 4.0 or higher. Yours is %s. |
|
13
|
|
|
|
|
|
|
Be prepared for trouble!", $BerkeleyDB::db_version if $BerkeleyDB::db_version<4; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Fcntl qw( SEEK_SET ); |
|
16
|
|
|
|
|
|
|
use MAB2::Record::Base; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $Rev = substr q$Rev:$, 5; |
|
19
|
|
|
|
|
|
|
our $VERSION = sprintf "%.02f", $Rev/100 + 0.3; # at 1.5 we left CVS |
|
20
|
|
|
|
|
|
|
# and came at 121 to |
|
21
|
|
|
|
|
|
|
# SVN |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub TIEHASH { |
|
25
|
|
|
|
|
|
|
my($class,%args) = @_; |
|
26
|
|
|
|
|
|
|
my $self = {}; |
|
27
|
|
|
|
|
|
|
$self->{ARGS} = \%args; |
|
28
|
|
|
|
|
|
|
die "Could not tie: required argument file missing" unless exists $args{file}; |
|
29
|
|
|
|
|
|
|
open my $fh, "<", $args{file} or Carp::confess("Could not open $args{file}: $!"); |
|
30
|
|
|
|
|
|
|
# warn sprintf "Filesize: %d\n", -s $fh; |
|
31
|
|
|
|
|
|
|
my %lookuprecno; |
|
32
|
|
|
|
|
|
|
# ("BerkeleyDB::Recno", -Filename => "$args{file}.bdbrecno", -Flags => DB_RDONLY, -Mode => 0600); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $db = tie(%lookuprecno, |
|
35
|
|
|
|
|
|
|
"BerkeleyDB::Hash", |
|
36
|
|
|
|
|
|
|
-Filename => "$args{file}.bdbrvi", |
|
37
|
|
|
|
|
|
|
-Flags => DB_RDONLY, |
|
38
|
|
|
|
|
|
|
-Mode => 0644); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#############################################^^^^^^^ did simply not work with RDONLY |
|
41
|
|
|
|
|
|
|
unless ($db) { |
|
42
|
|
|
|
|
|
|
$db = tie(%lookuprecno, |
|
43
|
|
|
|
|
|
|
"BerkeleyDB::Hash", |
|
44
|
|
|
|
|
|
|
-Filename => "$args{file}.bdbrvi", |
|
45
|
|
|
|
|
|
|
-Flags => DB_CREATE, |
|
46
|
|
|
|
|
|
|
-Mode => 0644) or die "Could not tie $args{file}.bdbhash: $!"; |
|
47
|
|
|
|
|
|
|
local($/) = "\n"; |
|
48
|
|
|
|
|
|
|
local($|) = 1; |
|
49
|
|
|
|
|
|
|
my $recno = 0; |
|
50
|
|
|
|
|
|
|
while (<$fh>) { |
|
51
|
|
|
|
|
|
|
chomp; |
|
52
|
|
|
|
|
|
|
my $obj = MAB2::Record::Base->new($_); |
|
53
|
|
|
|
|
|
|
$lookuprecno{$obj->id} = $recno++; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
my $stat = $db->db_stat(DB_FAST_STAT); |
|
57
|
|
|
|
|
|
|
# use Data::Dumper; |
|
58
|
|
|
|
|
|
|
# print Data::Dumper::Dumper($stat); |
|
59
|
|
|
|
|
|
|
$self->{LOOKUPRECNO} = \%lookuprecno; |
|
60
|
|
|
|
|
|
|
bless $self, ref $class || $class; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub UNTIE { |
|
64
|
|
|
|
|
|
|
my $self = shift; |
|
65
|
|
|
|
|
|
|
untie %{$self->{LOOKUPRECNO}}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub FETCH { |
|
69
|
|
|
|
|
|
|
my($self, $key) = @_; |
|
70
|
|
|
|
|
|
|
$self->{LOOKUPRECNO}{$key}; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
for my $method (qw(STORE DELETE CLEAR)) { |
|
74
|
|
|
|
|
|
|
no strict "refs"; |
|
75
|
|
|
|
|
|
|
*$method = sub { |
|
76
|
|
|
|
|
|
|
warn "$method not supported on ".ref shift; |
|
77
|
|
|
|
|
|
|
return; |
|
78
|
|
|
|
|
|
|
}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub EXISTS { |
|
82
|
|
|
|
|
|
|
my($self, $key) = @_; |
|
83
|
|
|
|
|
|
|
exists $self->{LOOKUPRECNO}{$key}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub NEXTKEY { |
|
87
|
|
|
|
|
|
|
my $self = shift; |
|
88
|
|
|
|
|
|
|
return each %{ $self->{LOOKUPRECNO} }; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub FIRSTKEY { |
|
92
|
|
|
|
|
|
|
my $self = shift; |
|
93
|
|
|
|
|
|
|
my $a = keys %{$self->{LOOKUPRECNO}}; |
|
94
|
|
|
|
|
|
|
return each %{ $self->{LOOKUPRECNO} }; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |