line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::MAB2::RecnoViaId; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1913
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
4
|
use Tie::Hash; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
29
|
our @ISA = qw(Tie::StdHash); |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
323
|
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: 333 $, 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
|
|
|
|
|
|
|
warn "Creating RVI index"; |
48
|
|
|
|
|
|
|
local($/) = "\n"; |
49
|
|
|
|
|
|
|
local($|) = 1; |
50
|
|
|
|
|
|
|
my $recno = 0; |
51
|
|
|
|
|
|
|
while (<$fh>) { |
52
|
|
|
|
|
|
|
chomp; |
53
|
|
|
|
|
|
|
my $obj = MAB2::Record::Base->new($_); |
54
|
|
|
|
|
|
|
$lookuprecno{$obj->id} = $recno++; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
my $stat = $db->db_stat(DB_FAST_STAT); |
58
|
|
|
|
|
|
|
# use Data::Dumper; |
59
|
|
|
|
|
|
|
# print Data::Dumper::Dumper($stat); |
60
|
|
|
|
|
|
|
$self->{LOOKUPRECNO} = \%lookuprecno; |
61
|
|
|
|
|
|
|
bless $self, ref $class || $class; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub UNTIE { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
untie %{$self->{LOOKUPRECNO}}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub FETCH { |
70
|
|
|
|
|
|
|
my($self, $key) = @_; |
71
|
|
|
|
|
|
|
$self->{LOOKUPRECNO}{$key}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
for my $method (qw(STORE DELETE CLEAR)) { |
75
|
|
|
|
|
|
|
no strict "refs"; |
76
|
|
|
|
|
|
|
*$method = sub { |
77
|
|
|
|
|
|
|
warn "$method not supported on ".ref shift; |
78
|
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub EXISTS { |
83
|
|
|
|
|
|
|
my($self, $key) = @_; |
84
|
|
|
|
|
|
|
exists $self->{LOOKUPRECNO}{$key}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub NEXTKEY { |
88
|
|
|
|
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
return each %{ $self->{LOOKUPRECNO} }; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub FIRSTKEY { |
93
|
|
|
|
|
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
my $a = keys %{$self->{LOOKUPRECNO}}; |
95
|
|
|
|
|
|
|
return each %{ $self->{LOOKUPRECNO} }; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |