| 1 | 28 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package DBIx::Squirrel::Util; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use Data::Dumper qw(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use Ref::Util qw(is_plain_arrayref is_plain_hashref is_plain_ref); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 28 | ▶ | use Sub::Util qw(set_subname subname); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 28 | ▶ | use Ekorn::Pipeline qw(is_stage); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 28 | ▶ | use DBIx::Squirrel::Errors qw(croakf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 28 | ▶ | use namespace::clean -except => 'import'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 28 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | canonical | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | install_sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | is_name | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | iterator_going | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | shift_attrs | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | split_attrs | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | split_stages | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | unwrap_values | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Croak at the line that called DBIx::Squirrel. | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 28 | our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Return options as a string, the same for the same options. | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 17 | ▶ | sub canonical ($options) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonical: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 17 | return Data::Dumper->new([$options])->Indent(0)->Sortkeys(1)->Terse(1)->Dump; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Install a subroutine by its full name. An anonymous one is given that | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # name, for stack traces; a named one keeps its own. | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 92 | ▶ | sub install_sub ($name, $code) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_sub: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 92 | ▶ | set_subname($name, $code) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | if subname($code) =~ m( :: __ANON__ \z )x; | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 28 | ▶ | no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 92 | *{ $name } = $code; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 92 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Return true if a name can be a subroutine's. | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 89 | ▶ | sub is_name ($name) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 89 | return $name =~ m( \A [^\W\d] \w* \z )x; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Return the iterator going through a statement handle's results, if one | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # has results left to hand out. | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 210 | ▶ | sub iterator_going ($sth) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterator_going: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 210 | ▶ | my $iterator = $sth->{private_ekorn}{Iterator} or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | return $iterator->{done} ? () : $iterator; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Take the attributes off the front of a list of arguments, if they're | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # there: a hash reference, or undef, as the DBI allows. An array reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # or a plain value there is a bind value, and is left in place, and so is | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # an object, whatever it's made of, as the DBI binds one as a value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1674 | ▶ | sub shift_attrs ($args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shift_attrs: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1674 | ▶ | return unless @$args; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1485 | my $first = $args->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1485 | ▶ | return shift @$args if !defined $first || is_plain_hashref($first); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $first or Ref::Util::XS::is_plain_hashref($first)
MC/DC100%2/2
not defined $first or Ref::Util::XS::is_plain_hashref($first)
not defined $first
Ref::Util::XS::is_plain_hashref($first)
Truth table100%3/3
not(A) or B
A= not defined $firstB= Ref::Util::XS::is_plain_hashref($first)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1254 | ▶ | croakf 'Expected a reference to a HASH or ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
Ref::Util::XS::is_plain_ref($first) and not Ref::Util::XS::is_plain_arrayref($first)
MC/DC100%2/2
Ref::Util::XS::is_plain_ref($first) and not Ref::Util::XS::is_plain_arrayref($first)
Ref::Util::XS::is_plain_ref($first)
not Ref::Util::XS::is_plain_arrayref($first)
Truth table100%3/3
A and not(B)
A= Ref::Util::XS::is_plain_ref($first)B= not Ref::Util::XS::is_plain_arrayref($first)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | if is_plain_ref($first) && !is_plain_arrayref($first); | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1252 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Split attributes into the DBI's and DBIx::Squirrel's own, those starting | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # "ekorn_", and return a reference to each. With no attributes, there are | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # none for the DBI: undef, as the DBI takes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1627 | ▶ | sub split_attrs ($attrs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_attrs: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1627 | ▶ | my %dbi = %{ $attrs // {} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs // {}
MC/DC100%1/1
$attrs // {}
$attrs
Truth table100%2/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1627 | my %ekorn = map { ($_ => delete $dbi{$_}) } grep { m( \A ekorn_ )x } keys %dbi; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1627 | ▶ | return $attrs && \%dbi, \%ekorn; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attrs && \%dbi
MC/DC100%1/1
$attrs && \%dbi
$attrs
Truth table100%2/2
A
A= $attrs
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Take the stages off the end of a list of arguments, and return them. A | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # stage is a code reference or a pipeline. | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1098 | ▶ | sub split_stages ($args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_stages: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1098 | my $n = @$args; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1098 | ▶ | $n -= 1 while $n && is_stage($args->[$n - 1]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n and is_stage($$args[$n - 1])
MC/DC100%2/2
$n and is_stage($$args[$n - 1])
$n
is_stage($$args[$n - 1])
Truth table100%3/3
A and B
A= $nB= is_stage($$args[$n - 1])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1098 | return splice @$args, $n; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Return the bind values given, or those in an array reference given | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # alone, unless it's a value itself. An object is a value, whatever it's | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # made of. Given to a statement taking one value, an array reference is | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # that value if the statement takes a list, as a list | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # placeholder does, or if the driver is DBD::Pg, which binds an array | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # reference as a PostgreSQL array, as it would with the DBI. The driver's | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # name is given, code returning how many values the statement takes, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # the statement's map of its list placeholders, if it has any. | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1288 | ▶ | sub unwrap_values ($driver, $taken, $lists, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unwrap_values: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | return @args | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1288 | ▶ | unless @args == 1 && is_plain_arrayref($args[0]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
MC/DC100%2/2
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
@args == 1
Ref::Util::XS::is_plain_arrayref($args[0])
Truth table100%3/3
A and B
A= @args == 1B= Ref::Util::XS::is_plain_arrayref($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | return @args | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 47 | ▶ | if ($lists || $driver eq 'Pg') && $taken->() == 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$lists || $driver eq "Pg" and &$taken() == 1
$lists or $driver eq "Pg"
MC/DC100%3/3
$lists || $driver eq "Pg" and &$taken() == 1
$lists
$driver eq "Pg"
&$taken() == 1
Truth table100%5/5
A or B and C
A= $listsB= $driver eq "Pg"C= &$taken() == 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 17 | return @{ $args[0] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 28 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||