blib/lib/DBIx/Squirrel/Util.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 18 / 18 Conditioncond 100% 22 / 22 MC/DCmcdc 100% 13 / 13 Subroutinesub 100% 17 / 17 Podpod 100% 8 / 8 totaltotal 100% 133 / 133 CC 18 SCAR 12.1
CC
18
Cov
100%
shift_attrs
6.0
unwrap_values
6.0
iterator_going
3.0
CRAP 3.4
« blib/lib/DBIx/Squirrel.pm ↑ Summary blib/lib/DBIx/Squirrel/Result.pm »
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
BranchTrueFalseTotal
if subname($code) =~ / :: __ANON__ \z /ux 72 20 92
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
BranchTrueFalseTotal
my $iterator = $sth->{"private_ekorn"}{"Iterator"} or return 6 204 210
54 6 ▶ return $iterator->{done} ? () : $iterator;
Branch: 1 branch
BranchTrueFalseTotal
$iterator->{'done'} ? : 1 5 6
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
BranchTrueFalseTotal
unless @$args 189 1485 1674
63 1485 my $first = $args->[0];
64 1485 ▶ return shift @$args if !defined $first || is_plain_hashref($first);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $first or Ref::Util::XS::is_plain_hashref($first) 231 1254 1485
Condition100%3/3
not defined $first or Ref::Util::XS::is_plain_hashref($first)
l!l&&r!l&&!r
181501254
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)
ABresult
1X1
011
000
65 1254 ▶ croakf 'Expected a reference to a HASH or ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_ref($first) and not Ref::Util::XS::is_plain_arrayref($first) 2 1252 1254
Condition100%3/3
Ref::Util::XS::is_plain_ref($first) and not Ref::Util::XS::is_plain_arrayref($first)
!ll&&!rl&&r
124392
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)
ABresult
0X0
100
111
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 // {}
l!l
2291398
MC/DC100%1/1
$attrs // {}
$attrs
Truth table100%2/2
A
A= $attrs
Aresult
11
00
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
!ll
1398229
MC/DC100%1/1
$attrs && \%dbi
$attrs
Truth table100%2/2
A
A= $attrs
Aresult
00
11
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
BranchTrueFalseTotal
$n and is_stage($$args[$n - 1]) and do { $n -= 1 } 1067 1098 2165
Condition100%3/3
$n and is_stage($$args[$n - 1])
!ll&&!rl&&r
5355631067
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])
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless @args == 1 and Ref::Util::XS::is_plain_arrayref($args[0]) 1241 47 1288
Condition100%3/3
@args == 1 and Ref::Util::XS::is_plain_arrayref($args[0])
!ll&&!rl&&r
43081147
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])
ABresult
0X0
100
111
98 return @args
99 47 ▶ if ($lists || $driver eq 'Pg') && $taken->() == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $lists || $driver eq "Pg" and &$taken() == 1 30 17 47
Condition100%6/6
$lists || $driver eq "Pg" and &$taken() == 1
!ll&&!rl&&r
12530
$lists or $driver eq "Pg"
l!l&&r!l&&!r
31412
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
ABCresult
00X0
1X00
0100
1X11
0111
100 17 return @{ $args[0] };
101 }
102  
103 28 1;
104 __END__
« blib/lib/DBIx/Squirrel.pm ↑ Summary blib/lib/DBIx/Squirrel/Result.pm »