ZofCMS/Plugin/DBI.pm

filter: Statementstmt 21.5% 20 / 93 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 54.5% 6 / 11 Podpod 50.0% 1 / 2 totaltotal 13.3% 27 / 203 CC 44 SCAR 53.9
CC
44
Cov
12%
_do_dbi_get
420.0
_do_dbi_set
156.0
process
132.0
CRAP 218.7
« ZofCMS/Plugin/FileUpload.pm ↑ Summary ZofCMS/Plugin/QuickNote.pm »
1 package App::ZofCMS::Plugin::DBI;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub new { bless {}, shift; }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=48.8
Pod documented
16 0 my ( $self, $template, $query, $config ) = @_;
17  
18 my $dbi_conf = {
19 do_dbi_set_first => 1,
20 0 ▶ %{ $config->conf->{dbi} || {} },
Condition0%0/2
$config->conf->{'dbi'} || {}
l!l
00
MC/DC0%0/1
$config->conf->{'dbi'} || {}
$config->conf->{'dbi'}
Truth table0%0/2
A
A= $config->conf->{'dbi'}
Aresult
11
00
21 0 ▶ %{ delete $template->{dbi} || {} },
Condition0%0/2
delete $template->{'dbi'} || {}
l!l
00
MC/DC0%0/1
delete $template->{'dbi'} || {}
delete $template->{'dbi'}
Truth table0%0/2
A
A= delete $template->{'dbi'}
Aresult
11
00
22 };
23  
24 0 ▶ $dbi_conf or return;
Branch: 1 branch
BranchTrueFalseTotal
$dbi_conf or return 0 0 0
25  
26 ( $dbi_conf->{dbi_set} or $dbi_conf->{dbi_get} )
27 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$dbi_conf->{"dbi_set"} or $dbi_conf->{"dbi_get"} or return 0 0 0
Condition0%0/3
$dbi_conf->{"dbi_set"} or $dbi_conf->{"dbi_get"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbi_conf->{"dbi_set"} or $dbi_conf->{"dbi_get"}
$dbi_conf->{"dbi_set"} $dbi_conf->{"dbi_get"}
Truth table0%0/3
A or B
A= $dbi_conf->{"dbi_set"}B= $dbi_conf->{"dbi_get"}
ABresult
1X1
011
000
28 my $dbh = DBI->connect_cached(
29 0 @$dbi_conf{ qw/dsn user pass opt/ }
30 );
31  
32 0 ▶ if ( $dbi_conf->{do_dbi_set_first} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_conf->{'do_dbi_set_first'}) { } 0 0 0
33 0 ▶ if ( $dbi_conf->{dbi_set} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_conf->{"dbi_set"}) 0 0 0
34 0 $self->_do_dbi_set( $dbi_conf, $query, $template, $config, $dbh );
35 }
36 0 ▶ if ( $dbi_conf->{dbi_get} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_conf->{"dbi_get"}) 0 0 0
37 0 $self->_do_dbi_get( $dbi_conf, $query, $template, $config, $dbh );
38 }
39 }
40 else {
41 0 ▶ if ( $dbi_conf->{dbi_get} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_conf->{"dbi_get"}) 0 0 0
42 0 $self->_do_dbi_get( $dbi_conf, $query, $template, $config, $dbh );
43 }
44 0 ▶ if ( $dbi_conf->{dbi_set} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbi_conf->{"dbi_set"}) 0 0 0
45 0 $self->_do_dbi_set( $dbi_conf, $query, $template, $config, $dbh );
46 }
47 }
48 }
49  
50 0 ▶sub _do_dbi_set {
Subroutine _do_dbi_set: not called CC=12 SCAR=50.5
51 0 my ( $self, $dbi_conf, $query, $template, $config, $dbh ) = @_;
52  
53 0 ▶ if ( ref $dbi_conf->{dbi_set} eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dbi_conf->{"dbi_set"} eq "CODE" or not ref $dbi_conf->{"dbi_set"}[0]) 0 0 0
Condition0%0/3
ref $dbi_conf->{"dbi_set"} eq "CODE" or not ref $dbi_conf->{"dbi_set"}[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $dbi_conf->{"dbi_set"} eq "CODE" or not ref $dbi_conf->{"dbi_set"}[0]
ref $dbi_conf->{"dbi_set"} eq "CODE" not ref $dbi_conf->{"dbi_set"}[0]
Truth table0%0/3
A or not(B)
A= ref $dbi_conf->{"dbi_set"} eq "CODE"B= not ref $dbi_conf->{"dbi_set"}[0]
ABresult
1X1
011
000
54 or not ref $dbi_conf->{dbi_set}[0]
55 ) {
56 0 $dbi_conf->{dbi_set} = [ $dbi_conf->{dbi_set} ];
57 }
58  
59 0 for my $set ( @{ $dbi_conf->{dbi_set} } ) {
60 0 ▶ if ( ref $set eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $set eq 'CODE') { } 0 0 0
61 0 my $sub_set_ref = $set->($query, $template, $config, $dbh );
62  
63 0 ▶ $sub_set_ref = [ $sub_set_ref ]
Branch: 1 branch
BranchTrueFalseTotal
unless not $sub_set_ref or ref $sub_set_ref eq "ARRAY" and ref $sub_set_ref->[0] eq "ARRAY" 0 0 0
Condition0%0/6
not $sub_set_ref or ref $sub_set_ref eq "ARRAY" and ref $sub_set_ref->[0] eq "ARRAY"
l!l&&r!l&&!r
000
ref $sub_set_ref eq "ARRAY" and ref $sub_set_ref->[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
not $sub_set_ref or ref $sub_set_ref eq "ARRAY" and ref $sub_set_ref->[0] eq "ARRAY"
not $sub_set_ref ref $sub_set_ref eq "ARRAY" ref $sub_set_ref->[0] eq "ARRAY"
Truth table0%0/4
not(A) or B and C
A= not $sub_set_refB= ref $sub_set_ref eq "ARRAY"C= ref $sub_set_ref->[0] eq "ARRAY"
ABCresult
1XX1
0111
00X0
0100
64 unless not $sub_set_ref
65 or ( ref $sub_set_ref eq 'ARRAY'
66 and ref $sub_set_ref->[0] eq 'ARRAY'
67 );
68 0 ▶ $dbh->do( @$_ ) for @{ $sub_set_ref || [] };
Condition0%0/2
$sub_set_ref || []
l!l
00
MC/DC0%0/1
$sub_set_ref || []
$sub_set_ref
Truth table0%0/2
A
A= $sub_set_ref
Aresult
11
00
69 }
70 else {
71 0 $dbh->do( @$set );
72 }
73 }
74 0 ▶ if ( defined $dbi_conf->{last_insert_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dbi_conf->{"last_insert_id"}) 0 0 0
75 $dbi_conf->{last_insert_id} = [
76 undef,
77 undef,
78 undef,
79 undef,
80 0 ▶ ] unless ref $dbi_conf->{last_insert_id};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dbi_conf->{"last_insert_id"} 0 0 0
81  
82 $template->{d}{last_insert_id} = $dbh->last_insert_id(
83 0 @{ $dbi_conf->{last_insert_id} }
84 );
85 }
86 }
87  
88 0 ▶sub _do_dbi_get {
Subroutine _do_dbi_get: not called CC=20 SCAR=60.4
89 0 my ( $self, $dbi_conf, $query, $template, $config, $dbh ) = @_;
90  
91 0 ▶ if ( ref $dbi_conf->{dbi_get} eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dbi_conf->{"dbi_get"} eq "CODE") 0 0 0
92 0 $dbi_conf->{dbi_get} = $dbi_conf->{dbi_get}->(
93 $query, $template, $config, $dbh
94 );
95 }
96  
97 0 ▶ if ( ref $dbi_conf->{dbi_get} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dbi_conf->{"dbi_get"} eq "HASH") 0 0 0
98 0 $dbi_conf->{dbi_get} = [ $dbi_conf->{dbi_get} ];
99 }
100  
101 0 for my $get ( @{ $dbi_conf->{dbi_get} } ) {
102 0 ▶ $get->{type} ||= 'loop';
Condition0%0/2
$get->{"type"} ||= "loop"
l!l
00
MC/DC0%0/1
$get->{"type"} ||= "loop"
$get->{"type"}
Truth table0%0/2
A
A= $get->{"type"}
Aresult
11
00
103 0 ▶ $get->{name} ||= 'dbi_var';
Condition0%0/2
$get->{"name"} ||= "dbi_var"
l!l
00
MC/DC0%0/1
$get->{"name"} ||= "dbi_var"
$get->{"name"}
Truth table0%0/2
A
A= $get->{"name"}
Aresult
11
00
104 0 ▶ $get->{method} ||= 'selectall';
Condition0%0/2
$get->{"method"} ||= "selectall"
l!l
00
MC/DC0%0/1
$get->{"method"} ||= "selectall"
$get->{"method"}
Truth table0%0/2
A
A= $get->{"method"}
Aresult
11
00
105 0 ▶ $get->{cell} ||= 't';
Condition0%0/2
$get->{"cell"} ||= "t"
l!l
00
MC/DC0%0/1
$get->{"cell"} ||= "t"
$get->{"cell"}
Truth table0%0/2
A
A= $get->{"cell"}
Aresult
11
00
106  
107 0 ▶ if ( $get->{type} eq 'loop' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get->{"type"} eq "loop") 0 0 0
108 0 my $data_ref;
109 0 ▶ if ( $get->{method} eq 'selectall' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get->{"method"} eq "selectall") 0 0 0
110 $data_ref = $dbh->selectall_arrayref(
111 0 @{ $get->{sql} },
112 );
113  
114 0 ▶ if ( $get->{process} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get->{"process"}) 0 0 0
115 0 $get->{process}->( $data_ref, $template, $query, $config );
116 }
117  
118 0 ▶ my $is_hash = ${ $get->{sql} || []}[1];
Condition0%0/2
$get->{'sql'} || []
l!l
00
MC/DC0%0/1
$get->{'sql'} || []
$get->{'sql'}
Truth table0%0/2
A
A= $get->{'sql'}
Aresult
11
00
119 0 ▶ $is_hash = ref $is_hash->{Slice} eq 'HASH' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $is_hash->{'Slice'} eq 'HASH' ? : 0 0 0
120  
121 0 ▶ if ( $get->{single} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get->{'single'}) { } 0 0 0
122  
123 my $loop_ref = $self->_prepare_loop_arrayref(
124 0 ▶ $data_ref, $get->{layout}, $is_hash
Condition0%0/2
$self->_prepare_loop_arrayref($data_ref, $get->{'layout'}, $is_hash)->[0] || {}
l!l
00
MC/DC0%0/1
$self->_prepare_loop_arrayref($data_ref, $get->{'layout'}, $is_hash)->[0] || {}
$self->_prepare_loop_arrayref($data_ref, $get->{'layout'}, $is_hash)->[0]
Truth table0%0/2
A
A= $self->_prepare_loop_arrayref($data_ref, $get->{'layout'}, $is_hash)->[0]
Aresult
11
00
125 )->[0] || {};
126  
127 0 ▶ if ( defined $get->{single_prefix} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $get->{"single_prefix"}) 0 0 0
128 0 my $pre = $get->{single_prefix};
129  
130 $loop_ref->{"$pre$_"}
131 = delete $loop_ref->{$_}
132 0 for keys %$loop_ref;
133 }
134  
135 $template->{ $get->{cell} }
136 = {
137 0 ▶ %{ $template->{ $get->{cell} } || {} },
Condition0%0/2
$$template{$get->{'cell'}} || {}
l!l
00
MC/DC0%0/1
$$template{$get->{'cell'}} || {}
$$template{$get->{'cell'}}
Truth table0%0/2
A
A= $$template{$get->{'cell'}}
Aresult
11
00
138 %$loop_ref,
139 };
140 }
141 else {
142 $template->{ $get->{cell} }{ $get->{name} }
143 = $self->_prepare_loop_arrayref(
144 $data_ref,
145 $get->{layout},
146 0 $is_hash,
147 );
148 }
149  
150 0 ▶ if ( $get->{on_data} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get->{"on_data"}) 0 0 0
151 0 ▶ $template->{t}{ $get->{on_data} } = 1
Branch: 1 branch
BranchTrueFalseTotal
if @$data_ref 0 0 0
152 if @$data_ref;
153 }
154 }
155 }
156 }
157 }
158  
159 0 ▶sub _prepare_loop_arrayref {
Subroutine _prepare_loop_arrayref: not called CC=4 SCAR=30.0
160 0 my ( $self, $data_ref, $layout_ref, $is_hash ) = @_;
161  
162 0 my @loop;
163 0 for my $entry_ref ( @$data_ref ) {
164 0 ▶ if ( $is_hash ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_hash) { } 0 0 0
165 0 ▶ if ( defined $layout_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $layout_ref) 0 0 0
166 0 @{ $entry_ref = {} }{ @$layout_ref } = @$entry_ref{ @$layout_ref };
167 }
168 0 push @loop, $entry_ref;
169 }
170 else {
171 0 push @loop, {
172 map +(
173 $layout_ref->[$_] => $entry_ref->[$_]
174 ), 0 .. $#$entry_ref
175 };
176 }
177 }
178  
179 0 return \@loop;
180 }
181  
182  
183 1 1;
184 __END__
« ZofCMS/Plugin/FileUpload.pm ↑ Summary ZofCMS/Plugin/QuickNote.pm »