Foo/SimpleQuery.pm

filter: Statementstmt 60.2% 44 / 73 Branchbran 46.1% 12 / 26 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 10 totaltotal 51.5% 68 / 132 CC 16 SCAR 15.4
CC
16
Cov
56%
dbh_do
8.0
selectrow
6.0
selectrow_hashref
6.0
CRAP 4.6
« Foo/UpdateQuery.pm ↑ Summary
1 package DBIx::Foo::SimpleQuery;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our @ISA = qw(Exporter);
10 4 our @EXPORT = qw(selectrow selectrow_array selectrow_hashref selectall selectall_arrayref selectall_hashref dbh_do);
11  
12 4 our $VERSION = '0.01';
13  
14  
15 sub selectrow
16 0 ▶{
Subroutine selectrow: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my ($self, $sql, $opts, @args) = @_;
18  
19 0 ▶ nice_params(\$opts, \@args) if scalar @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 0 0
20  
21 0 my $row = $self->dbh->selectrow_hashref($sql, $opts, @args);
22  
23 0 log_query($self->dbh, $sql, \@args);
24  
25 0 return $row;
26 }
27  
28 sub selectrow_hashref
29 0 ▶{
Subroutine selectrow_hashref: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my ($self, $sql, $opts, @args) = @_;
31  
32 0 ▶ nice_params(\$opts, \@args) if scalar @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 0 0
33  
34 0 my $row = $self->dbh->selectrow_hashref($sql, $opts, @args);
35  
36 0 log_query($self->dbh, $sql, \@args);
37  
38 0 return $row;
39 }
40  
41 sub selectrow_array
42 2 ▶{
Subroutine selectrow_array: called CC=3 SCAR=11.2
Pod undocumented
43 2 my ($self, $sql, $opts, @args) = @_;
44  
45 2 ▶ nice_params(\$opts, \@args) if scalar @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 2 2
46  
47 2 my @row = $self->dbh->selectrow_array($sql, $opts, @args);
48  
49 2 log_query($self->dbh, $sql, \@args);
50  
51 2 ▶ return $row[0] if scalar @row == 1; # for compatibility
Branch: 1 branch
BranchTrueFalseTotal
if scalar @row == 1 0 2 2
52  
53 2 return @row;
54 }
55  
56 sub selectall
57 0 ▶{
Subroutine selectall: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my ($self, $sql, @args) = @_;
59  
60 0 my $opts = { Slice => {} };
61  
62 0 my $rows = $self->dbh->selectall_arrayref($sql, $opts, @args);
63  
64 0 log_query($self->dbh, $sql, \@args);
65  
66 0 return $rows;
67 }
68  
69 sub selectall_arrayref
70 3 ▶{
Subroutine selectall_arrayref: called CC=2 SCAR=7.0
Pod undocumented
71 3 my ($self, $sql, $opts, @args) = @_;
72  
73 3 ▶ nice_params(\$opts, \@args) if scalar @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 0 3 3
74  
75 3 my $rows = $self->dbh->selectall_arrayref($sql, $opts, @args);
76  
77 3 log_query($self->dbh, $sql, \@args);
78  
79 3 return $rows;
80 }
81  
82 sub selectall_hashref
83 0 ▶{
Subroutine selectall_hashref: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my ($self, $sql, $key_field, $opts, @args) = @_;
85  
86 0 ▶ nice_params(\$opts, \@args) if scalar @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 3 0 0 0
87  
88 0 my $rows = $self->dbh->selectall_hashref($sql, $key_field, $opts, @args);
89  
90 0 log_query($self->dbh, $sql, \@args);
91  
92 0 return $rows;
93 }
94  
95 sub dbh_do
96 24 ▶{
Subroutine dbh_do: called CC=7 SCAR=20.7
Pod undocumented
97 24 my ($self, $sql, $opts, @args) = @_;
98  
99 24 ▶ nice_params(\$opts, \@args) if scalar @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 2 15 9 24
100  
101 # MSSQL insert requires extra SCOPE_IDENTITY() call to give inserted value - current best solution MT (only way I can make it work...)
102 24 ▶ if ($self->dbh->get_info(17) eq 'Microsoft SQL Server' && $sql =~ /^insert/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dbh->get_info(17) eq "Microsoft SQL Server" and $sql =~ /^insert/i) 0 24 24
Condition33%1/3
$self->dbh->get_info(17) eq "Microsoft SQL Server" and $sql =~ /^insert/i
!ll&&!rl&&r
2400
MC/DC0%0/2
$self->dbh->get_info(17) eq "Microsoft SQL Server" and $sql =~ /^insert/i
$self->dbh->get_info(17) eq "Microsoft SQL Server" $sql =~ /^insert/i
Truth table33%1/3
A and B
A= $self->dbh->get_info(17) eq "Microsoft SQL Server"B= $sql =~ /^insert/i
ABresult
0X0
100
111
103  
104 0 return mssql_insert($self->dbh, $sql, $opts, @args);
105 }
106  
107 24 my $result = $self->dbh->do($sql, $opts, @args);
108  
109 23 log_query($self->dbh, $sql, \@args);
110  
111 23 ▶ if ($result && $sql =~ /^insert into (\w+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result and $sql =~ /^insert into (\w+)/i) { } 19 4 23
Condition66%2/3
$result and $sql =~ /^insert into (\w+)/i
!ll&&!rl&&r
0419
MC/DC50%1/2
$result and $sql =~ /^insert into (\w+)/i
$result $sql =~ /^insert into (\w+)/i
Truth table66%2/3
A and B
A= $resultB= $sql =~ /^insert into (\w+)/i
ABresult
0X0
100
111
112  
113 19 ▶ if (my $newid = $self->dbh->last_insert_id(undef, undef, $1, undef)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $newid = $self->dbh->last_insert_id(undef, undef, $1, undef)) { } 19 0 19
114  
115 19 $log->debug("Got insertid : $newid");
116  
117 19 return $newid;
118 }
119 else {
120 0 return 1; # insert ok, but no insertid (not an auto inc)
121 }
122 }
123 else {
124  
125 4 return $result;
126 }
127 }
128  
129 sub mssql_insert
130 0 ▶{
Subroutine mssql_insert: not called CC=2 SCAR=17.9
Pod undocumented
131 0 my ($dbh, $sql, $opts, @args) = @_;
132  
133 0 ▶ $sql .= ';' unless $sql =~ /;\s*/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sql =~ /;\s*/ 0 0 0
134 0 $sql .= "select SCOPE_IDENTITY();";
135  
136 0 my $newid = $dbh->selectrow_array($sql, $opts, @args);
137  
138 0 log_query($dbh, $sql, \@args);
139  
140 0 return $newid;
141 }
142  
143 sub log_query
144 28 ▶{
Subroutine log_query: called CC=2 SCAR=7.4
Pod undocumented
145 28 my ($dbh, $sql, $args) = @_;
146  
147 # use the 'caller' function name to work out context
148 28 my $caller = ( caller(2) )[3];
149  
150 28 ▶ if ($dbh->err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->err) { } 0 28 28
151  
152 0 $log->error($dbh->errstr . " - $sql (" . join(",", @$args) . ") called by $caller");
153  
154 } else {
155  
156 28 $log->debug("$sql (" . join(",", @$args) . ") called by $caller");
157 }
158 }
159  
160 sub nice_params
161 15 ▶{
Subroutine nice_params: called CC=2 SCAR=6.9
Pod undocumented
162 15 my ($opts_ref, $args_ref) = @_;
163  
164 15 my $opts = $$opts_ref;
165  
166 #return unless defined $opts;
167  
168 15 ▶ unless (ref($opts) eq 'HASH') { #allow $opts hashref to be omitted
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opts eq "HASH") 12 3 15
169  
170 12 unshift @$args_ref, $opts;
171 12 $$opts_ref = {};
172  
173 12 $opts_ref = \$opts;
174 }
175 }
176  
177 4 1;
« Foo/UpdateQuery.pm ↑ Summary