blib/lib/DBD/DBM.pm

filter: Statementstmt 80.2% 231 / 288 Branchbran 51.7% 87 / 168 Conditioncond 38.2% 31 / 81 MC/DCmcdc 12.7% 6 / 47 Subroutinesub 82.3% 28 / 34 Podpod 0.0% 0 / 1 totaltotal 61.8% 383 / 619 CC 110 SCAR 32.7
CC
110
Cov
65%
open_data
75.7
bootstrap_table_meta
49.3
__ANON__
20.0
CRAP 26.3
« blib/lib/DBI/Gofer/Transport/Base.pm ↑ Summary blib/lib/DBI/PurePerl.pm »
1 #######################################################################
2 #
3 # DBD::DBM - a DBI driver for DBM files
4 #
5 # Copyright (c) 2004 by Jeff Zucker < jzucker AT cpan.org >
6 # Copyright (c) 2010-2013 by Jens Rehsack & H.Merijn Brand
7 #
8 # All rights reserved.
9 #
10 # You may freely distribute and/or modify this module under the terms
11 # of either the GNU General Public License (GPL) or the Artistic License,
12 # as specified in the Perl README file.
13 #
14 # USERS - see the pod at the bottom of this file
15 #
16 # DBD AUTHORS - see the comments in the code
17 #
18 #######################################################################
19 432 require 5.012;
20 432 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 432 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #################
24 package DBD::DBM;
25 #################
26 432 ▶use base qw( DBD::File );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 432 our ($drh,$methods_already_installed);
28 432 our $VERSION = '1.656';
29 432 our $ATTRIBUTION = 'DBD::DBM by Jens Rehsack';
30  
31 # no need to have driver() unless you need private methods
32 #
33 sub driver ($;$)
34 422 ▶{
Subroutine driver: called CC=3 SCAR=11.2
Pod undocumented
35 422 my ( $class, $attr ) = @_;
36 422 ▶ return $drh if ($drh);
Branch: 1 branch
BranchTrueFalseTotal
if $DBD::DBM::drh 0 422 422
37  
38 # do the real work in DBD::File
39 #
40 422 $attr->{Attribution} = 'DBD::DBM by Jens Rehsack';
41 422 $drh = $class->SUPER::driver($attr);
42  
43 # install private methods
44 #
45 # this requires that dbm_ (or foo_) be a registered prefix
46 # but you can write private methods before official registration
47 # by hacking the $dbd_prefix_registry in a private copy of DBI.pm
48 #
49 422 ▶ unless ( $methods_already_installed++ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($DBD::DBM::methods_already_installed++) 422 0 422
50 {
51 422 DBD::DBM::st->install_method('dbm_schema');
52 }
53  
54 422 return $drh;
55 }
56  
57 sub CLONE
58 0 ▶{
Subroutine CLONE: not called CC=1 SCAR=6.9
59 0 undef $drh;
60 }
61  
62 432 ▶if (eval { require Params::Util; }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Params::Util } }) { } 432 0 432
63 432 Params::Util->import ("_CLASS");
64 } else {
65 # SPDX-SnippetBegin
66 # SPDX-SnippetCopyrightText: 2005-2012 Adam Kennedy. 2020 Jens Rehsack.
67 # SPDX-License-Identifier: Artistic-1.0-Perl
68 # SPDX-PackageName: pkg:cpan/Params-Util@1.102
69 # SPDX-Description: taken from Params::Util::PP 1.102
70 0 ▶ *_CLASS = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
71 0 my $arg = $_[0];
72 0 ▶ return (defined $arg and not ref $arg and $arg =~ m/^[^\W\d]\w*(?:::\w+)*\z/s) ? $arg : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg && !ref($arg) && $arg =~ /^[^\W\d]\w*(?:::\w+)*\z/s ? : 0 0 0
Condition0%0/6
defined $arg and not ref $arg and $arg =~ /^[^\W\d]\w*(?:::\w+)*\z/s
!ll&&!rl&&r
000
defined $arg and not ref $arg
!ll&&!rl&&r
000
MC/DC0%0/3
defined $arg and not ref $arg and $arg =~ /^[^\W\d]\w*(?:::\w+)*\z/s
defined $arg not ref $arg $arg =~ /^[^\W\d]\w*(?:::\w+)*\z/s
Truth table0%0/4
A and not(B) and C
A= defined $argB= not ref $argC= $arg =~ /^[^\W\d]\w*(?:::\w+)*\z/s
ABCresult
0XX0
10X0
1100
1111
73 0 };
74 # SPDX-SnippetEnd
75 }
76  
77 #####################
78 package DBD::DBM::dr;
79 #####################
80 432 our $imp_data_size = 0;
81 432 our @ISA = qw(DBD::File::dr);
82  
83 # you could put some :dr private methods here
84  
85 # you may need to over-ride some DBD::File::dr methods here
86 # but you can probably get away with just letting it do the work
87 # in most cases
88  
89 #####################
90 package DBD::DBM::db;
91 #####################
92 432 our $imp_data_size = 0;
93 432 our @ISA = qw(DBD::File::db);
94  
95 432 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 432 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 sub validate_STORE_attr
99 7700 ▶{
Subroutine validate_STORE_attr: called CC=4 SCAR=20.4
100 7700 my ( $dbh, $attrib, $value ) = @_;
101  
102 7700 ▶ if ( $attrib eq "dbm_ext" or $attrib eq "dbm_lockfile" )
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "dbm_ext" or $attrib eq "dbm_lockfile") 0 7700 7700
Condition33%1/3
$attrib eq "dbm_ext" or $attrib eq "dbm_lockfile"
l!l&&r!l&&!r
007700
MC/DC0%0/2
$attrib eq "dbm_ext" or $attrib eq "dbm_lockfile"
$attrib eq "dbm_ext" $attrib eq "dbm_lockfile"
Truth table33%1/3
A or B
A= $attrib eq "dbm_ext"B= $attrib eq "dbm_lockfile"
ABresult
1X1
011
000
103 {
104 0 ( my $newattrib = $attrib ) =~ s/^dbm_/f_/g;
105 0 ▶ carp "Attribute '$attrib' is depreciated, use '$newattrib' instead" if ($^W);
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
106 0 $attrib = $newattrib;
107 }
108  
109 7700 return $dbh->SUPER::validate_STORE_attr( $attrib, $value );
110 }
111  
112 sub validate_FETCH_attr
113 0 ▶{
Subroutine validate_FETCH_attr: not called CC=4 SCAR=30.0
114 0 my ( $dbh, $attrib ) = @_;
115  
116 0 ▶ if ( $attrib eq "dbm_ext" or $attrib eq "dbm_lockfile" )
Branch: 1 branch
BranchTrueFalseTotal
if ($attrib eq "dbm_ext" or $attrib eq "dbm_lockfile") 0 0 0
Condition0%0/3
$attrib eq "dbm_ext" or $attrib eq "dbm_lockfile"
l!l&&r!l&&!r
000
MC/DC0%0/2
$attrib eq "dbm_ext" or $attrib eq "dbm_lockfile"
$attrib eq "dbm_ext" $attrib eq "dbm_lockfile"
Truth table0%0/3
A or B
A= $attrib eq "dbm_ext"B= $attrib eq "dbm_lockfile"
ABresult
1X1
011
000
117 {
118 0 ( my $newattrib = $attrib ) =~ s/^dbm_/f_/g;
119 0 ▶ carp "Attribute '$attrib' is depreciated, use '$newattrib' instead" if ($^W);
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
120 0 $attrib = $newattrib;
121 }
122  
123 0 return $dbh->SUPER::validate_FETCH_attr($attrib);
124 }
125  
126 sub set_versions
127 1054 ▶{
Subroutine set_versions: called CC=1 SCAR=0.0
128 1054 my $this = $_[0];
129 1054 $this->{dbm_version} = $DBD::DBM::VERSION;
130 1054 return $this->SUPER::set_versions();
131 }
132  
133 sub init_valid_attributes
134 1054 ▶{
Subroutine init_valid_attributes: called CC=1 SCAR=0.0
135 1054 my $dbh = shift;
136  
137 # define valid private attributes
138 #
139 # attempts to set non-valid attrs in connect() or
140 # with $dbh->{attr} will throw errors
141 #
142 # the attrs here *must* start with dbm_ or foo_
143 #
144 # see the STORE methods below for how to check these attrs
145 #
146 $dbh->{dbm_valid_attrs} = {
147 1054 dbm_type => 1, # the global DBM type e.g. SDBM_File
148 dbm_mldbm => 1, # the global MLDBM serializer
149 dbm_cols => 1, # the global column names
150 dbm_version => 1, # verbose DBD::DBM version
151 dbm_store_metadata => 1, # column names, etc.
152 dbm_berkeley_flags => 1, # for BerkeleyDB
153 dbm_valid_attrs => 1, # DBD::DBM::db valid attrs
154 dbm_readonly_attrs => 1, # DBD::DBM::db r/o attrs
155 dbm_meta => 1, # DBD::DBM public access for f_meta
156 dbm_tables => 1, # DBD::DBM public access for f_meta
157 dbm_updatable_key => 1,
158 };
159 $dbh->{dbm_readonly_attrs} = {
160 1054 dbm_version => 1, # verbose DBD::DBM version
161 dbm_valid_attrs => 1, # DBD::DBM::db valid attrs
162 dbm_readonly_attrs => 1, # DBD::DBM::db r/o attrs
163 dbm_meta => 1, # DBD::DBM public access for f_meta
164 };
165  
166 1054 $dbh->{dbm_meta} = "dbm_tables";
167  
168 1054 return $dbh->SUPER::init_valid_attributes();
169 }
170  
171 sub init_default_attributes
172 2108 ▶{
Subroutine init_default_attributes: called CC=1 SCAR=0.0
173 2108 my ( $dbh, $phase ) = @_;
174  
175 2108 $dbh->SUPER::init_default_attributes($phase);
176 2108 $dbh->{f_lockfile} = '.lck';
177  
178 2108 return $dbh;
179 }
180  
181 sub get_dbm_versions
182 16 ▶{
Subroutine get_dbm_versions: called CC=8 SCAR=28.8
183 16 my ( $dbh, $table ) = @_;
184 16 ▶ $table ||= '';
Condition50%1/2
$table ||= ""
l!l
016
MC/DC0%0/1
$table ||= ""
$table
Truth table50%1/2
A
A= $table
Aresult
11
00
185  
186 16 my $meta;
187 16 my $class = $dbh->{ImplementorClass};
188 16 $class =~ s/::db$/::Table/;
189 16 ▶ $table and ( undef, $meta ) = $class->get_table_meta( $dbh, $table, 1 );
Branch: 1 branch
BranchTrueFalseTotal
$table and (undef, $meta) = $class->get_table_meta($dbh, $table, 1) 0 16 16
190 16 ▶ $meta or ( $meta = {} and $class->bootstrap_table_meta( $dbh, $meta, $table ) );
Branch: 1 branch
BranchTrueFalseTotal
$meta or $meta = {} and $class->bootstrap_table_meta($dbh, $meta, $table) 0 16 16
Condition33%2/6
$meta || ($meta = {}) && $class->bootstrap_table_meta($dbh, $meta, $table)
l!l
0160
$meta = {} and $class->bootstrap_table_meta($dbh, $meta, $table)
!ll
0160
MC/DC0%0/3
$meta || ($meta = {}) && $class->bootstrap_table_meta($dbh, $meta, $table)
$meta $meta = {} $class->bootstrap_table_meta($dbh, $meta, $table)
Truth table0%0/4
A || B and C
A= $metaB= $meta = {}C= $class->bootstrap_table_meta($dbh, $meta, $table)
ABCresult
1XX1
0111
00X0
0100
191  
192 16 my $dver;
193 16 my $dtype = $meta->{dbm_type};
194 16 eval {
195 16 $dver = $meta->{dbm_type}->VERSION();
196  
197 # *) when we're still alive here, everything went ok - no need to check for $@
198 16 $dtype .= " ($dver)";
199 };
200 16 ▶ if ( $meta->{dbm_mldbm} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_mldbm"}) 0 16 16
201 {
202 0 $dtype .= ' + MLDBM';
203 0 eval {
204 0 $dver = MLDBM->VERSION();
205 0 $dtype .= " ($dver)"; # (*)
206 };
207 0 eval {
208 0 my $ser_class = "MLDBM::Serializer::" . $meta->{dbm_mldbm};
209 0 ▶ DBD::DBM::_CLASS($ser_class)
Branch: 1 branch
BranchTrueFalseTotal
&DBD::DBM::_CLASS($ser_class) or croak("Invalid dbm_mldbm '${ser_class}': expected a module name") 0 0 0
210 or croak "Invalid dbm_mldbm '$ser_class': expected a module name";
211 0 Module::Load::load $ser_class;
212 0 $dver = $ser_class->VERSION();
213 0 $dtype .= ' + ' . $ser_class; # (*)
214 0 ▶ $dver and $dtype .= " ($dver)"; # (*)
Branch: 1 branch
BranchTrueFalseTotal
$dver and $dtype .= " ($dver)" 0 0 0
215 };
216 }
217 16 return sprintf( "%s using %s", $dbh->{dbm_version}, $dtype );
218 }
219  
220 # you may need to over-ride some DBD::File::db methods here
221 # but you can probably get away with just letting it do the work
222 # in most cases
223  
224 #####################
225 package DBD::DBM::st;
226 #####################
227 432 our $imp_data_size = 0;
228 432 our @ISA = qw(DBD::File::st);
229  
230 sub FETCH
231 3922 ▶{
Subroutine FETCH: called CC=3 SCAR=11.0
232 3922 my ( $sth, $attr ) = @_;
233  
234 3922 ▶ if ( $attr eq "NULLABLE" )
Branch: 1 branch
BranchTrueFalseTotal
if ($attr eq "NULLABLE") 568 3354 3922
235 {
236 568 my @colnames = $sth->sql_get_colnames();
237  
238 # XXX only BerkeleyDB fails having NULL values for non-MLDBM databases,
239 # none accept it for key - but it requires more knowledge between
240 # queries and tables storage to return fully correct information
241 568 ▶ $attr eq "NULLABLE" and return [ map { 0 } @colnames ];
Branch: 1 branch
BranchTrueFalseTotal
$attr eq "NULLABLE" and return [map({0;} @colnames)] 568 0 568
242 }
243  
244 3354 return $sth->SUPER::FETCH($attr);
245 } # FETCH
246  
247 sub dbm_schema
248 0 ▶{
Subroutine dbm_schema: not called CC=3 SCAR=24.8
249 0 my ( $sth, $tname ) = @_;
250 0 ▶ return $sth->set_err( $DBI::stderr, 'No table name supplied!' ) unless $tname;
Branch: 1 branch
BranchTrueFalseTotal
unless $tname 0 0 0
251 my $tbl_meta = $sth->{Database}->func( $tname, "f_schema", "get_sql_engine_meta" )
252 0 ▶ or return $sth->set_err( $sth->{Database}->err(), $sth->{Database}->errstr() );
Branch: 1 branch
BranchTrueFalseTotal
my $tbl_meta = $sth->{"Database"}->func($tname, "f_schema", "get_sql_engine_meta") or return $sth->set_err($sth->{"Database"}->err, $sth->{"Database"}->errstr) 0 0 0
253 0 return $tbl_meta->{$tname}->{f_schema};
254 }
255 # you could put some :st private methods here
256  
257 # you may need to over-ride some DBD::File::st methods here
258 # but you can probably get away with just letting it do the work
259 # in most cases
260  
261 ############################
262 package DBD::DBM::Statement;
263 ############################
264  
265 432 our @ISA = qw(DBD::File::Statement);
266  
267 ########################
268 package DBD::DBM::Table;
269 ########################
270 432 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
271 432 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
272 432 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
273  
274 432 our @ISA = qw(DBD::File::Table);
275  
276 432 ▶my $dirfext = $^O eq 'VMS' ? '.sdbm_dir' : '.dir';
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'VMS' ? : 0 432 432
277  
278 432 my %reset_on_modify = (
279 dbm_type => "dbm_tietype",
280 dbm_mldbm => "dbm_tietype",
281 );
282 432 __PACKAGE__->register_reset_on_modify( \%reset_on_modify );
283  
284 my %compat_map = (
285 432 ( map { $_ => "dbm_$_" } qw(type mldbm store_metadata) ),
286 dbm_ext => 'f_ext',
287 dbm_file => 'f_file',
288 dbm_lockfile => ' f_lockfile',
289 );
290 432 __PACKAGE__->register_compat_map( \%compat_map );
291  
292 sub bootstrap_table_meta
293 724 ▶{
Subroutine bootstrap_table_meta: called CC=17 SCAR=39.0
294 724 my ( $self, $dbh, $meta, $table ) = @_;
295  
296 724 ▶ $meta->{dbm_type} ||= $dbh->{dbm_type} || 'SDBM_File';
Condition80%4/5
$meta->{"dbm_type"} ||= $dbh->{"dbm_type"} || "SDBM_File"
l!l&&r!l&&!r
187060
$dbh->{'dbm_type'} || 'SDBM_File'
l!l
532174
MC/DC0%0/2
$meta->{"dbm_type"} ||= $dbh->{"dbm_type"} || "SDBM_File"
$meta->{"dbm_type"} $dbh->{'dbm_type'}
Truth table66%2/3
A ||= B
A= $meta->{"dbm_type"}B= $dbh->{'dbm_type'}
ABresult
1X1
011
000
297 724 ▶ $meta->{dbm_mldbm} ||= $dbh->{dbm_mldbm} if ( $dbh->{dbm_mldbm} );
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->{"dbm_mldbm"} 0 724 724
Condition0%0/3
$meta->{"dbm_mldbm"} ||= $dbh->{"dbm_mldbm"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$meta->{"dbm_mldbm"} ||= $dbh->{"dbm_mldbm"}
$meta->{"dbm_mldbm"} $dbh->{"dbm_mldbm"}
Truth table0%0/3
A ||= B
A= $meta->{"dbm_mldbm"}B= $dbh->{"dbm_mldbm"}
ABresult
1X1
011
000
298 724 ▶ $meta->{dbm_berkeley_flags} ||= $dbh->{dbm_berkeley_flags};
Condition33%1/3
$meta->{"dbm_berkeley_flags"} ||= $dbh->{"dbm_berkeley_flags"}
l!l&&r!l&&!r
00724
MC/DC0%0/2
$meta->{"dbm_berkeley_flags"} ||= $dbh->{"dbm_berkeley_flags"}
$meta->{"dbm_berkeley_flags"} $dbh->{"dbm_berkeley_flags"}
Truth table33%1/3
A ||= B
A= $meta->{"dbm_berkeley_flags"}B= $dbh->{"dbm_berkeley_flags"}
ABresult
1X1
011
000
299  
300 724 ▶ $meta->{f_ext} //= $dbh->{f_ext};
Condition66%2/3
$meta->{"f_ext"} //= $dbh->{"f_ext"}
l!l&&r!l&&!r
100714
MC/DC50%1/2
$meta->{"f_ext"} //= $dbh->{"f_ext"}
$meta->{"f_ext"} $dbh->{"f_ext"}
Truth table66%2/3
A //= B
A= $meta->{"f_ext"}B= $dbh->{"f_ext"}
ABresult
1X1
011
000
301 724 ▶ unless ( defined( $meta->{f_ext} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"f_ext"}) 714 10 724
302 {
303 714 my $ext;
304 714 ▶ if ( $meta->{dbm_type} eq 'SDBM_File' or $meta->{dbm_type} eq 'ODBM_File' )
Branch: 2 branches
BranchTrueFalseTotal
if ($meta->{'dbm_type'} eq 'SDBM_File' or $meta->{'dbm_type'} eq 'ODBM_File') { } 674 40 714
elsif ($meta->{'dbm_type'} eq 'NDBM_File') { } 0 40 40
Condition66%2/3
$meta->{"dbm_type"} eq "SDBM_File" or $meta->{"dbm_type"} eq "ODBM_File"
l!l&&r!l&&!r
674040
MC/DC50%1/2
$meta->{"dbm_type"} eq "SDBM_File" or $meta->{"dbm_type"} eq "ODBM_File"
$meta->{"dbm_type"} eq "SDBM_File" $meta->{"dbm_type"} eq "ODBM_File"
Truth table66%2/3
A or B
A= $meta->{"dbm_type"} eq "SDBM_File"B= $meta->{"dbm_type"} eq "ODBM_File"
ABresult
1X1
011
000
305 {
306 674 $ext = '.pag/r';
307 }
308 elsif ( $meta->{dbm_type} eq 'NDBM_File' )
309 {
310 # XXX NDBM_File on FreeBSD (and elsewhere?) may actually be Berkeley
311 # behind the scenes and so create a single .db file.
312 0 ▶ if ( $^O =~ /bsd/i or lc($^O) eq 'darwin' )
Branch: 2 branches
BranchTrueFalseTotal
if ($^O =~ /bsd/i or lc $^O eq 'darwin') { } 0 0 0
elsif ($^O eq 'SunOS' or $^O eq 'Solaris' or $^O eq 'AIX') { } 0 0 0
Condition0%0/3
$^O =~ /bsd/i or lc $^O eq "darwin"
l!l&&r!l&&!r
000
MC/DC0%0/2
$^O =~ /bsd/i or lc $^O eq "darwin"
$^O =~ /bsd/i lc $^O eq "darwin"
Truth table0%0/3
A or B
A= $^O =~ /bsd/iB= lc $^O eq "darwin"
ABresult
1X1
011
000
313 {
314 0 $ext = '.db/r';
315 }
316 ▶ elsif ( $^O eq 'SunOS' or $^O eq 'Solaris' or $^O eq 'AIX' )
Condition0%0/6
$^O eq "SunOS" or $^O eq "Solaris" or $^O eq "AIX"
l!l&&r!l&&!r
000
$^O eq "SunOS" or $^O eq "Solaris"
l!l&&r!l&&!r
000
MC/DC0%0/3
$^O eq "SunOS" or $^O eq "Solaris" or $^O eq "AIX"
$^O eq "SunOS" $^O eq "Solaris" $^O eq "AIX"
Truth table0%0/4
A or B or C
A= $^O eq "SunOS"B= $^O eq "Solaris"C= $^O eq "AIX"
ABCresult
1XX1
01X1
0011
0000
317 {
318 0 $ext = '.pag/r'; # here it's implemented like dbm - just a bit improved
319 }
320 # else wrapped GDBM
321 }
322 714 ▶ defined($ext) and $meta->{f_ext} = $ext;
Branch: 1 branch
BranchTrueFalseTotal
defined $ext and $meta->{"f_ext"} = $ext 674 40 714
323 }
324  
325 724 $self->SUPER::bootstrap_table_meta( $dbh, $meta, $table );
326 }
327  
328 sub init_table_meta
329 590 ▶{
Subroutine init_table_meta: called CC=11 SCAR=24.8
330 590 my ( $self, $dbh, $meta, $table ) = @_;
331  
332 590 $meta->{f_dontopen} = 1;
333  
334 590 ▶ unless ( defined( $meta->{dbm_tietype} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"dbm_tietype"}) 560 30 590
335 {
336 560 my $tie_type = $meta->{dbm_type};
337 560 ▶ DBD::DBM::_CLASS($tie_type)
Branch: 1 branch
BranchTrueFalseTotal
&DBD::DBM::_CLASS($tie_type) or croak("Invalid dbm_type '${tie_type}': expected a module name") 528 32 560
338 or croak "Invalid dbm_type '$tie_type': expected a module name";
339 528 Module::Load::load $tie_type;
340 528 ▶ $tie_type eq 'BerkeleyDB' and $tie_type = 'BerkeleyDB::Hash';
Branch: 1 branch
BranchTrueFalseTotal
$tie_type eq "BerkeleyDB" and $tie_type = "BerkeleyDB::Hash" 0 528 528
341  
342 528 ▶ if ( $meta->{dbm_mldbm} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_mldbm"}) 0 528 528
343 {
344 0 Module::Load::load "MLDBM";
345 0 $meta->{dbm_usedb} = $tie_type;
346 0 $tie_type = 'MLDBM';
347 }
348  
349 528 $meta->{dbm_tietype} = $tie_type;
350 }
351  
352 558 ▶ unless ( defined( $meta->{dbm_store_metadata} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"dbm_store_metadata"}) 528 30 558
353 {
354 528 my $store = $dbh->{dbm_store_metadata};
355 528 ▶ defined($store) or $store = 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $store or $store = 1 0 528 528
356 528 $meta->{dbm_store_metadata} = $store;
357 }
358  
359 558 ▶ unless ( defined( $meta->{col_names} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"col_names"}) 540 18 558
360 {
361 540 ▶ defined( $dbh->{dbm_cols} ) and $meta->{col_names} = $dbh->{dbm_cols};
Branch: 1 branch
BranchTrueFalseTotal
defined $dbh->{"dbm_cols"} and $meta->{"col_names"} = $dbh->{"dbm_cols"} 0 540 540
362 }
363  
364 558 ▶ unless ( defined( $meta->{dbm_updatable_key} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"dbm_updatable_key"}) 558 0 558
365 {
366 558 ▶ defined( $dbh->{dbm_updatable_key} ) and $meta->{dbm_updatable_key} = $dbh->{dbm_updatable_key};
Branch: 1 branch
BranchTrueFalseTotal
defined $dbh->{"dbm_updatable_key"} and $meta->{"dbm_updatable_key"} = $dbh->{"dbm_updatable_key"} 12 546 558
367 }
368  
369 558 $self->SUPER::init_table_meta( $dbh, $meta, $table );
370 }
371  
372 sub open_data
373 920 ▶{
Subroutine open_data: called CC=27 SCAR=43.3
374 920 my ( $className, $meta, $attrs, $flags ) = @_;
375  
376 # Validate dbm_mldbm BEFORE SUPER::open_data creates and flock()s the
377 # lock file. A croak after that point leaves $meta->{lockfh} holding an
378 # exclusive lock for as long as the table meta data lives, and the next
379 # open of the same table in this process blocks on it forever.
380 920 ▶ if ( $meta->{dbm_mldbm} and not $flags->{dropMode} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_mldbm"} and not $flags->{"dropMode"}) 0 920 920
Condition33%1/3
$meta->{"dbm_mldbm"} and not $flags->{"dropMode"}
!ll&&!rl&&r
92000
MC/DC0%0/2
$meta->{"dbm_mldbm"} and not $flags->{"dropMode"}
$meta->{"dbm_mldbm"} not $flags->{"dropMode"}
Truth table33%1/3
A and not(B)
A= $meta->{"dbm_mldbm"}B= not $flags->{"dropMode"}
ABresult
0X0
100
111
381 {
382 DBD::DBM::_CLASS( $meta->{dbm_mldbm} )
383 0 ▶ or croak "Invalid dbm_mldbm '$meta->{dbm_mldbm}': expected a module name";
Branch: 1 branch
BranchTrueFalseTotal
&DBD::DBM::_CLASS($meta->{"dbm_mldbm"}) or croak(qq[Invalid dbm_mldbm '$meta->{"dbm_mldbm"}': expected a module name]) 0 0 0
384 }
385  
386 920 $className->SUPER::open_data( $meta, $attrs, $flags );
387  
388 820 ▶ unless ( $flags->{dropMode} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($flags->{"dropMode"}) 704 116 820
389 {
390 # TIEING
391 #
392 # XXX allow users to pass in a pre-created tied object
393 #
394 704 my @tie_args;
395 704 ▶ if ( $meta->{dbm_type} eq 'BerkeleyDB' )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'dbm_type'} eq 'BerkeleyDB') { } 0 704 704
396 {
397 0 my $DB_CREATE = BerkeleyDB::DB_CREATE();
398 0 my $DB_RDONLY = BerkeleyDB::DB_RDONLY();
399 0 my %tie_flags;
400 0 ▶ if ( my $f = $meta->{dbm_berkeley_flags} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $meta->{"dbm_berkeley_flags"}) 0 0 0
401 {
402 0 ▶ defined( $f->{DB_CREATE} ) and $DB_CREATE = delete $f->{DB_CREATE};
Branch: 1 branch
BranchTrueFalseTotal
defined $f->{"DB_CREATE"} and $DB_CREATE = delete $f->{"DB_CREATE"} 0 0 0
403 0 ▶ defined( $f->{DB_RDONLY} ) and $DB_RDONLY = delete $f->{DB_RDONLY};
Branch: 1 branch
BranchTrueFalseTotal
defined $f->{"DB_RDONLY"} and $DB_RDONLY = delete $f->{"DB_RDONLY"} 0 0 0
404 0 %tie_flags = %$f;
405 }
406 0 ▶ my $open_mode = $flags->{lockMode} || $flags->{createMode} ? $DB_CREATE : $DB_RDONLY;
Branch: 1 branch
BranchTrueFalseTotal
$flags->{'lockMode'} || $flags->{'createMode'} ? : 0 0 0
Condition0%0/3
$flags->{"lockMode"} or $flags->{"createMode"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags->{"lockMode"} or $flags->{"createMode"}
$flags->{"lockMode"} $flags->{"createMode"}
Truth table0%0/3
A or B
A= $flags->{"lockMode"}B= $flags->{"createMode"}
ABresult
1X1
011
000
407 @tie_args = (
408 -Filename => $meta->{f_fqbn},
409 0 -Flags => $open_mode,
410 %tie_flags
411 );
412 }
413 else
414 {
415 704 my $open_mode = O_RDONLY;
416 704 ▶ $flags->{lockMode} and $open_mode = O_RDWR;
Branch: 1 branch
BranchTrueFalseTotal
$flags->{"lockMode"} and $open_mode = 2 494 210 704
417 704 ▶ $flags->{createMode} and $open_mode = O_RDWR | O_CREAT | O_TRUNC;
Branch: 1 branch
BranchTrueFalseTotal
$flags->{"createMode"} and $open_mode = 578 122 582 704
418  
419 704 @tie_args = ( $meta->{f_fqbn}, $open_mode, 0666 );
420 }
421  
422 704 ▶ if ( $meta->{dbm_mldbm} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_mldbm"}) 0 704 704
423 {
424 0 $MLDBM::UseDB = $meta->{dbm_usedb};
425 0 $MLDBM::Serializer = $meta->{dbm_mldbm};
426 }
427  
428 704 $meta->{hash} = {};
429 704 my $tie_class = $meta->{dbm_tietype};
430 704 eval { tie %{ $meta->{hash} }, $tie_class, @tie_args };
431 704 ▶ if ( $@ or not -f $meta->{f_fqfn} )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not -f $meta->{"f_fqfn"}) 0 704 704
Condition33%1/3
$@ or not -f $meta->{"f_fqfn"}
l!l&&r!l&&!r
00704
MC/DC0%0/2
$@ or not -f $meta->{"f_fqfn"}
$@ not -f $meta->{"f_fqfn"}
Truth table33%1/3
A or not(B)
A= $@B= not -f $meta->{"f_fqfn"}
ABresult
1X1
011
000
432 {
433 # Release the lock SUPER::open_data took, or it outlives this
434 # failure (see above).
435 my $err = $@ ? "Cannot tie(\%h $tie_class @tie_args): $@"
436 0 ▶ : "No such file: '" . $meta->{f_fqfn} . "'";
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
437 0 $className->_release_lock($meta);
438 0 croak $err;
439 }
440 }
441  
442 820 ▶ unless ( $flags->{createMode} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($flags->{"createMode"}) 698 122 820
443 {
444 698 my ( $meta_data, $schema, $col_names );
445 698 ▶ if ( $meta->{dbm_store_metadata} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_store_metadata"}) 698 0 698
446 {
447 698 $meta_data = $col_names = $meta->{hash}->{"_metadata \0"};
448 698 ▶ if ( $meta_data and $meta_data =~ m~<dbd_metadata>(.+)</dbd_metadata>~is )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta_data and $meta_data =~ m[<dbd_metadata>(.+)</dbd_metadata>]is) 582 116 698
Condition66%2/3
$meta_data and $meta_data =~ m[<dbd_metadata>(.+)</dbd_metadata>]is
!ll&&!rl&&r
1160582
MC/DC50%1/2
$meta_data and $meta_data =~ m[<dbd_metadata>(.+)</dbd_metadata>]is
$meta_data $meta_data =~ m[<dbd_metadata>(.+)</dbd_metadata>]is
Truth table66%2/3
A and B
A= $meta_dataB= $meta_data =~ m[<dbd_metadata>(.+)</dbd_metadata>]is
ABresult
0X0
100
111
449 {
450 582 $schema = $col_names = $1;
451 582 $schema =~ s~.*<schema>(.+)</schema>.*~$1~is;
452 582 $col_names =~ s~.*<col_names>(.+)</col_names>.*~$1~is;
453 }
454 }
455 698 ▶ $col_names ||= $meta->{col_names} || [ 'k', 'v' ];
Condition80%4/5
$col_names ||= $meta->{"col_names"} || ["k", "v"]
l!l&&r!l&&!r
5821160
$meta->{'col_names'} || ['k', 'v']
l!l
6452
MC/DC0%0/2
$col_names ||= $meta->{"col_names"} || ["k", "v"]
$col_names $meta->{'col_names'}
Truth table66%2/3
A ||= B
A= $col_namesB= $meta->{'col_names'}
ABresult
1X1
011
000
456 698 ▶ $col_names = [ split /,/, $col_names ] if ( ref $col_names ne 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $col_names ne "ARRAY" 582 116 698
457 698 ▶ if ( $meta->{dbm_store_metadata} and not $meta->{hash}->{"_metadata \0"} )
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"dbm_store_metadata"} and not $meta->{"hash"}{"_metadata \0"}) 116 582 698
Condition66%2/3
$meta->{"dbm_store_metadata"} and not $meta->{"hash"}{"_metadata \0"}
!ll&&!rl&&r
0582116
MC/DC50%1/2
$meta->{"dbm_store_metadata"} and not $meta->{"hash"}{"_metadata \0"}
$meta->{"dbm_store_metadata"} not $meta->{"hash"}{"_metadata \0"}
Truth table66%2/3
A and not(B)
A= $meta->{"dbm_store_metadata"}B= not $meta->{"hash"}{"_metadata \0"}
ABresult
0X0
100
111
458 {
459 116 ▶ $schema or $schema = '';
Branch: 1 branch
BranchTrueFalseTotal
$schema or $schema = "" 0 116 116
460 $meta->{hash}->{"_metadata \0"} =
461 "<dbd_metadata>"
462 . "<schema>$schema</schema>"
463 . "<col_names>"
464 116 . join( ",", @{$col_names} )
465 . "</col_names>"
466 . "</dbd_metadata>";
467 }
468  
469 698 $meta->{schema} = $schema;
470 698 $meta->{col_names} = $col_names;
471 }
472 }
473  
474 # you must define drop
475 # it is called from execute of a SQL DROP statement
476 #
477 sub drop ($$)
478 116 ▶{
Subroutine drop: called CC=4 SCAR=14.8
479 116 my ( $self, $data ) = @_;
480 116 my $meta = $self->{meta};
481 116 ▶ $meta->{hash} and untie %{ $meta->{hash} };
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"hash"} and untie %{$$meta{"hash"};} 116 0 116
482 116 $self->SUPER::drop($data);
483 # XXX extra_files
484 -f $meta->{f_fqbn} . $dirfext
485 and $meta->{f_ext} eq '.pag/r'
486 116 ▶ and unlink( $meta->{f_fqbn} . $dirfext );
Branch: 1 branch
BranchTrueFalseTotal
-f $meta->{"f_fqbn"} . $dirfext and $meta->{"f_ext"} eq ".pag/r" and unlink $meta->{"f_fqbn"} . $dirfext 116 0 116
Condition33%1/3
-f $meta->{"f_fqbn"} . $dirfext and $meta->{"f_ext"} eq ".pag/r"
!ll&&!rl&&r
00116
MC/DC0%0/2
-f $meta->{"f_fqbn"} . $dirfext and $meta->{"f_ext"} eq ".pag/r"
-f $meta->{"f_fqbn"} . $dirfext $meta->{"f_ext"} eq ".pag/r"
Truth table33%1/3
A and B
A= -f $meta->{"f_fqbn"} . $dirfextB= $meta->{"f_ext"} eq ".pag/r"
ABresult
0X0
100
111
487 116 return 1;
488 }
489  
490 # you must define fetch_row, it is called on all fetches;
491 # it MUST return undef when no rows are left to fetch;
492 # checking for $ary[0] is specific to hashes so you'll
493 # probably need some other kind of check for nothing-left.
494 # as Janis might say: "undef's just another word for
495 # nothing left to fetch" :-)
496 #
497 sub fetch_row ($$)
498 1022 ▶{
Subroutine fetch_row: called CC=8 SCAR=21.0
499 1022 my ( $self, $data ) = @_;
500 1022 my $meta = $self->{meta};
501 # fetch with %each
502 #
503 1022 my @ary = each %{ $meta->{hash} };
504 $meta->{dbm_store_metadata}
505 and $ary[0]
506 and $ary[0] eq "_metadata \0"
507 1022 ▶ and @ary = each %{ $meta->{hash} };
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"dbm_store_metadata"} and $ary[0] and $ary[0] eq "_metadata \0" and @ary = each %{$$meta{"hash"};} 326 696 1022
Condition83%5/6
$meta->{"dbm_store_metadata"} and $ary[0] and $ary[0] eq "_metadata \0"
!ll&&!rl&&r
290406326
$meta->{"dbm_store_metadata"} and $ary[0]
!ll&&!rl&&r
0290732
MC/DC66%2/3
$meta->{"dbm_store_metadata"} and $ary[0] and $ary[0] eq "_metadata \0"
$meta->{"dbm_store_metadata"} $ary[0] $ary[0] eq "_metadata \0"
Truth table75%3/4
A and B and C
A= $meta->{"dbm_store_metadata"}B= $ary[0]C= $ary[0] eq "_metadata \0"
ABCresult
0XX0
10X0
1100
1111
508  
509 1022 my ( $key, $val ) = @ary;
510 1022 ▶ unless ($key)
Branch: 1 branch
BranchTrueFalseTotal
unless ($key) 290 732 1022
511 {
512 290 delete $self->{row};
513 290 return;
514 }
515 732 ▶ my @row = ( ref($val) eq 'ARRAY' ) ? ( $key, @$val ) : ( $key, $val );
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 732 732
516 732 ▶ $self->{row} = @row ? \@row : undef;
Branch: 1 branch
BranchTrueFalseTotal
@row ? : 732 0 732
517 732 ▶ return wantarray ? @row : \@row;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 732 732
518 }
519  
520 # you must define push_row except insert_new_row and update_specific_row is defined
521 # it is called on inserts and updates as primitive
522 #
523 sub insert_new_row ($$$)
524 256 ▶{
Subroutine insert_new_row: called CC=4 SCAR=14.0
525 256 my ( $self, $data, $row_aryref ) = @_;
526 256 my $meta = $self->{meta};
527 256 my $ncols = scalar( @{ $meta->{col_names} } );
528 256 my $nitems = scalar( @{$row_aryref} );
529 256 ▶ $ncols == $nitems
Branch: 1 branch
BranchTrueFalseTotal
$ncols == $nitems or croak("You tried to insert $nitems, but table is created with $ncols columns") 256 0 256
530 or croak "You tried to insert $nitems, but table is created with $ncols columns";
531  
532 256 my $key = shift @$row_aryref;
533 256 my $exists;
534 256 eval { $exists = exists( $meta->{hash}->{$key} ); };
535 256 ▶ $exists and croak "Row with PK '$key' already exists";
Branch: 1 branch
BranchTrueFalseTotal
$exists and croak("Row with PK '${key}' already exists") 0 256 256
536  
537 256 ▶ $meta->{hash}->{$key} = $meta->{dbm_mldbm} ? $row_aryref : $row_aryref->[0];
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'dbm_mldbm'} ? : 0 256 256
538  
539 256 return 1;
540 }
541  
542 # this is where you grab the column names from a CREATE statement
543 # if you don't need to do that, it must be defined but can be empty
544 #
545 sub push_names ($$$)
546 122 ▶{
Subroutine push_names: called CC=6 SCAR=18.7
547 122 my ( $self, $data, $row_aryref ) = @_;
548 122 my $meta = $self->{meta};
549  
550 # some sanity checks ...
551 122 my $ncols = scalar(@$row_aryref);
552 122 ▶ $ncols < 2 and croak "At least 2 columns are required for DBD::DBM tables ...";
Branch: 1 branch
BranchTrueFalseTotal
$ncols < 2 and croak("At least 2 columns are required for DBD::DBM tables ...") 0 122 122
553 !$meta->{dbm_mldbm}
554 122 ▶ and $ncols > 2
Branch: 1 branch
BranchTrueFalseTotal
not $meta->{"dbm_mldbm"} and $ncols > 2 and croak("Without serializing with MLDBM only 2 columns are supported, you give $ncols") 0 122 122
Condition33%1/3
not $meta->{"dbm_mldbm"} and $ncols > 2
!ll&&!rl&&r
01220
MC/DC0%0/2
not $meta->{"dbm_mldbm"} and $ncols > 2
not $meta->{"dbm_mldbm"} $ncols > 2
Truth table33%1/3
not(A) and B
A= not $meta->{"dbm_mldbm"}B= $ncols > 2
ABresult
0X0
100
111
555 and croak "Without serializing with MLDBM only 2 columns are supported, you give $ncols";
556 122 $meta->{col_names} = $row_aryref;
557 122 ▶ return unless $meta->{dbm_store_metadata};
Branch: 1 branch
BranchTrueFalseTotal
unless $meta->{"dbm_store_metadata"} 0 122 122
558  
559 122 my $stmt = $data->{sql_stmt};
560 122 my $col_names = join( ',', @{$row_aryref} );
561 122 my $schema = $data->{Database}->{Statement};
562 122 $schema =~ s/^[^\(]+\((.+)\)$/$1/s;
563 122 ▶ $schema = $stmt->schema_str() if ( $stmt->can('schema_str') );
Branch: 1 branch
BranchTrueFalseTotal
if $stmt->can("schema_str") 0 122 122
564 122 $meta->{hash}->{"_metadata \0"} =
565 "<dbd_metadata>"
566 . "<schema>$schema</schema>"
567 . "<col_names>$col_names</col_names>"
568 . "</dbd_metadata>";
569 }
570  
571 # fetch_one_row, delete_one_row, update_one_row
572 # are optimized for hash-style lookup without looping;
573 # if you don't need them, omit them, they're optional
574 # but, in that case you may need to define
575 # truncate() and seek(), see below
576 #
577 sub fetch_one_row ($$;$)
578 272 ▶{
Subroutine fetch_one_row: called CC=5 SCAR=16.7
579 272 my ( $self, $key_only, $key ) = @_;
580 272 my $meta = $self->{meta};
581 272 ▶ $key_only and return $meta->{col_names}->[0];
Branch: 1 branch
BranchTrueFalseTotal
$key_only and return $meta->{"col_names"}[0] 236 36 272
582 36 ▶ exists $meta->{hash}->{$key} or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $meta->{"hash"}{$key} or return 36 0 36
583 36 my $val = $meta->{hash}->{$key};
584 36 ▶ $val = ( ref($val) eq 'ARRAY' ) ? $val : [$val];
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 36 36
585 36 my $row = [ $key, @$val ];
586 0 ▶ return wantarray ? @{$row} : $row;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 36 36
587 }
588  
589 sub delete_one_row ($$$)
590 56 ▶{
Subroutine delete_one_row: called CC=1 SCAR=0.0
591 56 my ( $self, $data, $aryref ) = @_;
592 56 my $meta = $self->{meta};
593 56 delete $meta->{hash}->{ $aryref->[0] };
594 }
595  
596 sub update_one_row ($$$)
597 0 ▶{
Subroutine update_one_row: not called CC=4 SCAR=30.0
598 0 my ( $self, $data, $aryref ) = @_;
599 0 my $meta = $self->{meta};
600 0 my $key = shift @$aryref;
601 0 ▶ defined $key or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $key or return 0 0 0
602 0 ▶ my $row = ( ref($aryref) eq 'ARRAY' ) ? $aryref : [$aryref];
Branch: 1 branch
BranchTrueFalseTotal
ref $aryref eq 'ARRAY' ? : 0 0 0
603 0 ▶ $meta->{hash}->{$key} = $meta->{dbm_mldbm} ? $row : $row->[0];
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'dbm_mldbm'} ? : 0 0 0
604 }
605  
606 sub update_specific_row ($$$$)
607 164 ▶{
Subroutine update_specific_row: called CC=9 SCAR=22.7
608 164 my ( $self, $data, $aryref, $origary ) = @_;
609 164 my $meta = $self->{meta};
610 164 my $key = shift @$origary;
611 164 my $newkey = shift @$aryref;
612 164 ▶ return unless ( defined $key );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 164 164
613  
614 164 ▶ if ( my $mode = $meta->{dbm_updatable_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mode = $meta->{"dbm_updatable_key"}) 8 156 164
615 4 ▶ my $method = $mode == 1 ? \&carp : sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
616 4 ▶ warn $_[0] if $] < 5.013002;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.013002" 0 4 4
617 4 croak $_[0];
618 8 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mode == 1 ? : 4 4 8
619 8 my $exists;
620 8 ▶ eval { $exists = $key ne $newkey && exists( $meta->{hash}->{$newkey} ); };
Condition33%1/3
$key ne $newkey && exists $meta->{'hash'}{$newkey}
!ll&&!rl&&r
008
MC/DC0%0/2
$key ne $newkey && exists $meta->{'hash'}{$newkey}
$key ne $newkey exists $meta->{'hash'}{$newkey}
Truth table33%1/3
A && B
A= $key ne $newkeyB= exists $meta->{'hash'}{$newkey}
ABresult
0X0
100
111
621 8 ▶ $exists and $method->("Row with PK '$newkey' already exists");
Branch: 1 branch
BranchTrueFalseTotal
$exists and &$method("Row with PK '${newkey}' already exists") 8 0 8
622 }
623  
624 160 ▶ $key eq $newkey or delete $meta->{hash}->{$key};
Branch: 1 branch
BranchTrueFalseTotal
$key eq $newkey or delete $meta->{"hash"}{$key} 152 8 160
625 160 ▶ my $row = ( ref($aryref) eq 'ARRAY' ) ? $aryref : [$aryref];
Branch: 1 branch
BranchTrueFalseTotal
ref $aryref eq 'ARRAY' ? : 160 0 160
626 160 ▶ $meta->{hash}->{$newkey} = $meta->{dbm_mldbm} ? $row : $row->[0];
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'dbm_mldbm'} ? : 0 160 160
627 }
628  
629 # you may not need to explicitly DESTROY the ::Table
630 # put cleanup code to run when the execute is done
631 #
632 sub DESTROY ($)
633 820 ▶{
Subroutine DESTROY: called CC=2 SCAR=7.0
634 820 my $self = shift;
635 820 my $meta = $self->{meta};
636 820 ▶ $meta->{hash} and untie %{ $meta->{hash} };
Branch: 1 branch
BranchTrueFalseTotal
$meta->{"hash"} and untie %{$$meta{"hash"};} 820 0 820
637  
638 820 $self->SUPER::DESTROY();
639 }
640  
641 # truncate() and seek() must be defined to satisfy DBI::SQL::Nano
642 # *IF* you define the *_one_row methods above, truncate() and
643 # seek() can be empty or you can use them without actually
644 # truncating or seeking anything but if you don't define the
645 # *_one_row methods, you may need to define these
646  
647 # if you need to do something after a series of
648 # deletes or updates, you can put it in truncate()
649 # which is called at the end of executing
650 #
651 sub truncate ($$)
652 0 ▶{
Subroutine truncate: not called CC=1 SCAR=6.9
653 # my ( $self, $data ) = @_;
654 0 return 1;
655 }
656  
657 # seek() is only needed if you use IO::File
658 # though it could be used for other non-file operations
659 # that you need to do before "writes" or truncate()
660 #
661 sub seek ($$$$)
662 256 ▶{
Subroutine seek: called CC=1 SCAR=0.0
663 # my ( $self, $data, $pos, $whence ) = @_;
664 256 return 1;
665 }
666  
667 # Th, th, th, that's all folks! See DBD::File and DBD::CSV for other
668 # examples of creating pure perl DBDs. I hope this helped.
669 # Now it's time to go forth and create your own DBD!
670 # Remember to check in with dbi-dev@perl.org before you get too far.
671 # We may be able to make suggestions or point you to other related
672 # projects.
673  
674 432 1;
675 __END__
« blib/lib/DBI/Gofer/Transport/Base.pm ↑ Summary blib/lib/DBI/PurePerl.pm »