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