line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
26
|
use strict; use warnings; |
|
4
|
|
|
4
|
|
8
|
|
|
4
|
|
|
|
|
107
|
|
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
169
|
|
2
|
|
|
|
|
|
|
package IO::All::DBM; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
938
|
use IO::All::File -base; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
56
|
|
5
|
4
|
|
|
4
|
|
31
|
use Fcntl; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
3482
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
field _dbm_list => []; |
8
|
|
|
|
|
|
|
field '_dbm_class'; |
9
|
|
|
|
|
|
|
field _dbm_extra => []; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub dbm { |
12
|
2
|
|
|
2
|
1
|
46
|
my $self = shift; |
13
|
2
|
|
|
|
|
11
|
bless $self, __PACKAGE__; |
14
|
2
|
|
|
|
|
13
|
$self->_dbm_list([@_]); |
15
|
2
|
|
|
|
|
19
|
return $self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _assert_open { |
19
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
20
|
5
|
100
|
|
|
|
20
|
return $self->tied_file |
21
|
|
|
|
|
|
|
if $self->tied_file; |
22
|
2
|
|
|
|
|
8
|
$self->open; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub assert_filepath { |
26
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
27
|
1
|
|
|
|
|
8
|
$self->SUPER::assert_filepath(@_); |
28
|
1
|
50
|
33
|
|
|
12
|
if ($self->_rdonly and not -e $self->pathname) { |
29
|
0
|
|
|
|
|
0
|
my $rdwr = $self->_rdwr; |
30
|
0
|
|
|
|
|
0
|
$self->assert(0)->rdwr(1)->rdonly(0)->open; |
31
|
0
|
|
|
|
|
0
|
$self->close; |
32
|
0
|
|
|
|
|
0
|
$self->assert(1)->rdwr($rdwr)->rdonly(1); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub open { |
37
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
38
|
2
|
|
|
|
|
14
|
$self->is_open(1); |
39
|
2
|
50
|
|
|
|
8
|
return $self->tied_file if $self->tied_file; |
40
|
2
|
100
|
|
|
|
20
|
$self->assert_filepath if $self->_assert; |
41
|
2
|
|
|
|
|
13
|
my $dbm_list = $self->_dbm_list; |
42
|
2
|
100
|
|
|
|
13
|
my @dbm_list = @$dbm_list ? @$dbm_list : |
43
|
|
|
|
|
|
|
(qw(DB_File GDBM_File NDBM_File ODBM_File SDBM_File)); |
44
|
2
|
|
|
|
|
5
|
my $dbm_class; |
45
|
2
|
|
|
|
|
7
|
for my $module (@dbm_list) { |
46
|
6
|
|
|
|
|
32
|
(my $file = "$module.pm") =~ s{::}{/}g; |
47
|
6
|
100
|
66
|
2
|
|
372
|
if (defined $INC{$file} || eval "eval 'use $module; 1'") { |
|
2
|
|
|
1
|
|
870
|
|
|
1
|
|
|
1
|
|
1645
|
|
|
1
|
|
|
1
|
|
23
|
|
|
1
|
|
|
1
|
|
375
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
351
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
364
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
858
|
|
|
1
|
|
|
|
|
2659
|
|
|
1
|
|
|
|
|
35
|
|
48
|
2
|
|
|
|
|
16
|
$self->_dbm_class($module); |
49
|
2
|
|
|
|
|
7
|
last; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
2
|
50
|
|
|
|
12
|
$self->throw("No module available for IO::All DBM operation") |
53
|
|
|
|
|
|
|
unless defined $self->_dbm_class; |
54
|
2
|
50
|
|
|
|
15
|
my $mode = $self->_rdonly ? O_RDONLY : O_RDWR; |
55
|
2
|
50
|
|
|
|
10
|
if ($self->_dbm_class eq 'DB_File::Lock') { |
56
|
0
|
|
|
|
|
0
|
$self->_dbm_class->import; |
57
|
0
|
0
|
|
|
|
0
|
my $type = eval '$DB_HASH'; die $@ if $@; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
# XXX Not sure about this warning |
59
|
0
|
0
|
0
|
|
|
0
|
warn "Using DB_File::Lock in IO::All without the rdonly or rdwr method\n" |
60
|
|
|
|
|
|
|
if not ($self->_rdwr or $self->_rdonly); |
61
|
0
|
0
|
|
|
|
0
|
my $flag = $self->_rdwr ? 'write' : 'read'; |
62
|
0
|
0
|
|
|
|
0
|
$mode = $self->_rdwr ? O_RDWR : O_RDONLY; |
63
|
0
|
|
|
|
|
0
|
$self->_dbm_extra([$type, $flag]); |
64
|
|
|
|
|
|
|
} |
65
|
2
|
50
|
|
|
|
13
|
$mode |= O_CREAT if $mode & O_RDWR; |
66
|
2
|
|
|
|
|
19
|
$self->mode($mode); |
67
|
2
|
50
|
|
|
|
12
|
$self->perms(0666) unless defined $self->perms; |
68
|
2
|
|
|
|
|
10
|
return $self->tie_dbm; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub tie_dbm { |
72
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
73
|
2
|
|
|
|
|
5
|
my $hash; |
74
|
2
|
|
|
|
|
10
|
my $filename = $self->name; |
75
|
|
|
|
|
|
|
my $db = tie %$hash, $self->_dbm_class, $filename, $self->mode, $self->perms, |
76
|
2
|
50
|
|
|
|
10
|
@{$self->_dbm_extra} |
|
2
|
|
|
|
|
10
|
|
77
|
|
|
|
|
|
|
or $self->throw("Can't open '$filename' as DBM file:\n$!"); |
78
|
2
|
50
|
|
|
|
26
|
$self->add_utf8_dbm_filter($db) |
79
|
|
|
|
|
|
|
if $self->_has_utf8; |
80
|
2
|
|
|
|
|
11
|
$self->tied_file($hash); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub add_utf8_dbm_filter { |
84
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
85
|
0
|
|
|
|
|
0
|
my $db = shift; |
86
|
0
|
|
|
0
|
|
0
|
$db->filter_store_key(sub { utf8::encode($_) }); |
|
0
|
|
|
|
|
0
|
|
87
|
0
|
|
|
0
|
|
0
|
$db->filter_store_value(sub { utf8::encode($_) }); |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
0
|
|
0
|
$db->filter_fetch_key(sub { utf8::decode($_) }); |
|
0
|
|
|
|
|
0
|
|
89
|
0
|
|
|
0
|
|
0
|
$db->filter_fetch_value(sub { utf8::decode($_) }); |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |