| 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
Condition0%0/6
builtin::blessed($bind) and $bind->can("value_ref") and $bind->can("type")
builtin::blessed($bind) and $bind->can("value_ref")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 13 | ▶ | if (@bind == 1 && ref $bind[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@bind == 1 and ref $bind[0] eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $bind and ref $bind eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||