| 1 | package DBIx::Sunny::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use SQL::NamedPlaceholder 0.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | our @EXPORT_OK = qw/bind_and_execute expand_placeholder/; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub bind_and_execute { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | my ($sth, @bind) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_and_execute: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | for my $bind ( @bind ) { | |||||||||||||||||||||||||||||||||||||||||
| 16 | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | # If $bind is an SQL::Maker::SQLType or compatible object, use its type info. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $sth->bind_param(++$i, ${ $bind->value_ref }, $bind->type); | |||||||||||||||||||||||||||||||||||||||||
| 19 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $sth->bind_param(++$i, $bind); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return $sth->execute; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub expand_placeholder { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my ($query, @bind) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_placeholder: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | return if ! defined $query; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if (@bind == 1 && ref $bind[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and B
A= @bind == 1B= ref $bind[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ($query, my $bind_param) = SQL::NamedPlaceholder::bind_named($query, $bind[0]); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return $query, @$bind_param; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my @bind_param; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $query =~ s{\?}{ | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $bind = shift @bind; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (ref($bind) && ref($bind) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $bind and ref $bind eq "ARRAY"
MC/DC0%0/2
ref $bind and ref $bind eq "ARRAY"
ref $bind
ref $bind eq "ARRAY"
Truth table0%0/3
A and B
A= ref $bindB= ref $bind eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | push @bind_param, @$bind; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | join ',', ('?') x @$bind; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | push @bind_param, $bind; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | '?'; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | }ge; | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return ( $query, @bind_param ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | 1 | |||||||||||||||||||||||||||||||||||||||||