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