blib/lib/DBIx/Sunny/Util.pm

filter: Statementstmt 78.7% 37 / 47 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 4 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 2 totaltotal 63.9% 55 / 86 CC 11 SCAR 24.4
CC
11
Cov
68%
bind_and_execute
30.0
expand_placeholder
7.3
BEGIN
1.0
CRAP 11.5
« blib/lib/DBIx/Sunny.pm ↑ Summary Build »
1 package DBIx::Sunny::Util;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use SQL::NamedPlaceholder 0.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 our @EXPORT_OK = qw/bind_and_execute expand_placeholder/;
12  
13 sub bind_and_execute {
14 0 ▶ my ($sth, @bind) = @_;
Subroutine bind_and_execute: not called CC=5 SCAR=34.0
Pod undocumented
15 0 my $i = 0;
16 0 for my $bind ( @bind ) {
17 0 ▶ if ( blessed($bind) && $bind->can('value_ref') && $bind->can('type') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($bind) and $bind->can('value_ref') and $bind->can('type')) { } 0 0 0
Condition0%0/6
builtin::blessed($bind) and $bind->can("value_ref") and $bind->can("type")
!ll&&!rl&&r
000
builtin::blessed($bind) and $bind->can("value_ref")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($bind) and $bind->can("value_ref") and $bind->can("type")
builtin::blessed($bind) $bind->can("value_ref") $bind->can("type")
Truth table0%0/4
A and B and C
A= builtin::blessed($bind)B= $bind->can("value_ref")C= $bind->can("type")
ABCresult
0XX0
10X0
1100
1111
18 # If $bind is an SQL::Maker::SQLType or compatible object, use its type info.
19 0 $sth->bind_param(++$i, ${ $bind->value_ref }, $bind->type);
20 } else {
21 0 $sth->bind_param(++$i, $bind);
22 }
23 }
24 0 return $sth->execute;
25 }
26  
27 sub expand_placeholder {
28 13 ▶ my ($query, @bind) = @_;
Subroutine expand_placeholder: called CC=7 SCAR=19.9
Pod undocumented
29  
30 13 ▶ return if ! defined $query;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $query 0 13 13
31 13 ▶ if (@bind == 1 && ref $bind[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@bind == 1 and ref $bind[0] eq "HASH") 0 13 13
Condition66%2/3
@bind == 1 and ref $bind[0] eq "HASH"
!ll&&!rl&&r
760
MC/DC0%0/2
@bind == 1 and ref $bind[0] eq "HASH"
@bind == 1 ref $bind[0] eq "HASH"
Truth table66%2/3
A and B
A= @bind == 1B= ref $bind[0] eq "HASH"
ABresult
0X0
100
111
32 0 ($query, my $bind_param) = SQL::NamedPlaceholder::bind_named($query, $bind[0]);
33 0 return $query, @$bind_param;
34 }
35  
36 13 my @bind_param;
37 13 my $orig_num_binds = @bind;
38 13 my $num_bounds = 0;
39 13 $query =~ s{\?}{
40 10 my $bind = shift @bind;
41 10 $num_bounds++;
42 10 ▶ if (ref($bind) && ref($bind) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bind and ref $bind eq 'ARRAY') { } 4 6 10
Condition66%2/3
ref $bind and ref $bind eq "ARRAY"
!ll&&!rl&&r
604
MC/DC50%1/2
ref $bind and ref $bind eq "ARRAY"
ref $bind ref $bind eq "ARRAY"
Truth table66%2/3
A and B
A= ref $bindB= ref $bind eq "ARRAY"
ABresult
0X0
100
111
43 4 push @bind_param, @$bind;
44 4 join ',', ('?') x @$bind;
45 } else {
46 6 push @bind_param, $bind;
47 6 '?';
48 }
49 }ge;
50  
51 13 ▶ if ($num_bounds != $orig_num_binds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_bounds != $orig_num_binds) 8 5 13
52 8 croak "Num of binds doesn't match. expected = $num_bounds, but passed $orig_num_binds";
53 }
54  
55 5 return ( $query, @bind_param );
56 }
57  
58 12 1
« blib/lib/DBIx/Sunny.pm ↑ Summary Build »