| 1 | 9 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package DBIx::Squirrel::Sugar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Ref::Util qw(is_arrayref is_hashref is_plain_hashref is_ref); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Ekorn::Pipeline qw(is_stage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Ekorn::Pipeline::Sugar qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use DBIx::Squirrel qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use DBIx::Squirrel::Errors qw(at_caller croakf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use DBIx::Squirrel::Util qw(install_sub is_name shift_attrs split_stages); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Croak at the line that called DBIx::Squirrel. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Each database defined, by name: the arguments to connect with, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # handle, once it's connected. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | my %connect_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | my %handle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Give the calling package database or statement, and define the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # databases or statements named in a hash reference after each, with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # their arguments in an array reference. The pipelines after each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # pipeline go to Ekorn::Pipeline::Sugar first, wherever they're given, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # so a statement can name one (roadmap 2026-0027). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | ▶ | sub import ($class, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 23 | state %define = (database => \&_define, statement => \&_define_statement); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 23 | state %what = (database => 'arguments to connect to', statement => 'statement'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 23 | my $package = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 23 | my(@pipelines, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 23 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 38 | my $arg = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 38 | ▶ | if (defined $arg && $arg eq 'pipeline') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $arg and $arg eq "pipeline"
MC/DC50%1/2
defined $arg and $arg eq "pipeline"
defined $arg
$arg eq "pipeline"
Truth table66%2/3
A and B
A= defined $argB= $arg eq "pipeline"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 6 | push @pipelines, $arg, shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 32 | push @rest, $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | at_caller { Ekorn::Pipeline::Sugar->import_into($package, @pipelines) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 23 | ▶ | if @pipelines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 19 | @args = @rest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | ▶ | while (@args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 24 | my $arg = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | croakf 'Expected database, pipeline or statement, not %s', $arg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 24 | ▶ | unless $define{$arg}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 23 | _install($package, $arg => $class->can($arg)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 23 | ▶ | next unless @args && is_hashref($args[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args and Ref::Util::XS::is_hashref($args[0])
MC/DC100%2/2
@args and Ref::Util::XS::is_hashref($args[0])
@args
Ref::Util::XS::is_hashref($args[0])
Truth table100%3/3
A and B
A= @argsB= Ref::Util::XS::is_hashref($args[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | my $definitions = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | for my $name (sort keys %$definitions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | croakf 'Expected the %s %s in an ARRAY', $what{$arg}, $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 14 | ▶ | unless is_arrayref($definitions->{$name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 12 | $define{$arg}->($package, $name, @{ $definitions->{$name} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # Return the handle of the database named, or, given the arguments to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # connect with, define it, give the calling package a function of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # name, and return that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # The handle is kept, and given again without asking the database, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # would cost a round trip each time, unless it's been disconnected, or its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # last call failed, when it's pinged, and replaced if it doesn't answer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Neither DBD::mysql nor DBD::Pg turns Active off when the server drops | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # the connection, but each leaves the failure in err. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 456 | ▶ | sub database ($name, @connect) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
database: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 456 | ▶ | return _define(scalar caller, $name, @connect) if @connect; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | croakf 'Expected a database named %s', $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 436 | ▶ | unless $connect_args{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 434 | my $dbh = $handle{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | return $dbh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 434 | ▶ | if $dbh && $dbh->{Active} && (!$dbh->err || _answers($dbh)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$dbh and $dbh->{"Active"} and !$dbh->err || _answers($dbh)
$dbh and $dbh->{"Active"}
not $dbh->err or _answers($dbh)
MC/DC100%4/4
$dbh and $dbh->{"Active"} and !$dbh->err || _answers($dbh)
$dbh
$dbh->{"Active"}
not $dbh->err
_answers($dbh)
Truth table100%5/5
A and B and not(C) or D
A= $dbhB= $dbh->{"Active"}C= not $dbh->errD= _answers($dbh)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 21 | my($source, @rest) = @{ $connect_args{$name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 21 | ▶ | my $method = $source isa 'DBI::db' ? 'connect' : 'connect_cached'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 21 | return $handle{$name} = DBIx::Squirrel->$method($source, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Return true if a database answers a ping. A ping that dies, as the DBI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # allows, is no answer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | ▶ | sub _answers ($dbh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_answers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 8 | my $answered = eval { $dbh->ping }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | return $answered; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Define a statement on a database, with the attributes to prepare it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # with and stages, if given, give the calling package a function of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # name, and return that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 23 | ▶ | sub statement ($name, $database, $statement, @rest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statement: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 22 | return _define_statement(scalar caller, $name, $database, $statement, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # Define a database, and give a package a function of its name, returning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # the function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 22 | ▶ | sub _define ($package, $name, @connect) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_define: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 22 | ▶ | croakf 'Expected a name for a database (%s)', $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | unless is_name($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | croakf 'Expected a database defined once (%s)', $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 21 | ▶ | if $connect_args{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 20 | ▶ | my $function = sub (@args) { _run($name, @args) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bands: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 20 | _install($package, $name, $function); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 19 | $connect_args{$name} = \@connect; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 19 | return $function; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Define a statement, and give a package a function of its name, returning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # the function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 32 | ▶ | sub _define_statement ($package, $name, @definition) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_define_statement: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 32 | my($database, $statement, @rest) = @definition; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 32 | ▶ | croakf 'Expected a name for a statement (%s)', $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | unless is_name($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 31 | ▶ | croakf 'Expected a database and a statement for %s', $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $database and defined $statement
MC/DC50%1/2
defined $database and defined $statement
defined $database
defined $statement
Truth table66%2/3
A and B
A= defined $databaseB= defined $statement
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | unless defined $database && defined $statement; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Only a plain hash is the attributes: a pipeline, or any other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # object, straight after the statement is a stage, or a mistake. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 30 | ▶ | my $attrs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@rest and !defined($rest[0]) || Ref::Util::XS::is_plain_hashref($rest[0])
not defined $rest[0] or Ref::Util::XS::is_plain_hashref($rest[0])
MC/DC100%3/3
@rest and !defined($rest[0]) || Ref::Util::XS::is_plain_hashref($rest[0])
@rest
not defined $rest[0]
Ref::Util::XS::is_plain_hashref($rest[0])
Truth table100%4/4
A and not(B) or C
A= @restB= not defined $rest[0]C= Ref::Util::XS::is_plain_hashref($rest[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | = @rest && (!defined $rest[0] || is_plain_hashref($rest[0])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ? shift @rest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | croakf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | "Expected only stages after the statement for %s: code references, pipelines or their names, or objects offering a stage's role method", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 30 | ▶ | if grep { !is_stage($_) && !_is_pipeline_name($_) } @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_stage($_) || _is_pipeline_name($_)
MC/DC100%2/2
is_stage($_) || _is_pipeline_name($_)
is_stage($_)
_is_pipeline_name($_)
Truth table100%3/3
A || B
A= is_stage($_)B= _is_pipeline_name($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 26 | @rest = map { _resolved($package, $_) } @rest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 25 | my %definition = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | database => $database, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | statement => $statement, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | attrs => $attrs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | stages => \@rest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 25 | ▶ | my $function = sub (@args) { _run_statement(\%definition, @args) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 25 | _install($package, $name, $function); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 23 | return $function; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Return true if a stage given in a definition is a pipeline's name: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # words joined by ::, as Ekorn::Pipeline names them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 36 | ▶ | sub _is_pipeline_name ($stage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_pipeline_name: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 36 | ▶ | defined $stage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
defined $stage && !Ref::Util::XS::is_ref($stage) && $stage =~ / \A [^\W\d]\w* (?: :: [^\W\d]\w* )* \z /ax
defined $stage and not Ref::Util::XS::is_ref($stage)
MC/DC66%2/3
defined $stage && !Ref::Util::XS::is_ref($stage) && $stage =~ / \A [^\W\d]\w* (?: :: [^\W\d]\w* )* \z /ax
defined $stage
not Ref::Util::XS::is_ref($stage)
$stage =~ / \A [^\W\d]\w* (?: :: [^\W\d]\w* )* \z /ax
Truth table75%3/4
A and not(B) && C
A= defined $stageB= not Ref::Util::XS::is_ref($stage)C= $stage =~ / \A [^\W\d]\w* (?: :: [^\W\d]\w* )* \z /ax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | && !is_ref($stage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | && $stage =~ m( \A [^\W\d]\w* (?: :: [^\W\d]\w* )* \z )xa; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # Return a stage given in a definition: a pipeline's name resolved now, in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # the package making the definition, as Ekorn::Pipeline's pipeline word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # resolves one in its caller's, each on its own, so the other stages keep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # their places; anything else as it is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 25 | ▶ | sub _resolved ($package, $stage) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolved: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 25 | ▶ | return $stage unless _is_pipeline_name($stage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ▶ | return at_caller { Ekorn::Pipeline->pipeline_in($package, $stage) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Run a statement's function: execute the statement with the bind values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # given, and return its handle, or, with stages, its own or those given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # after the bind values, return an iterator over the results, or, if the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # last stage is a sink, its result. The statement is prepared | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # once for each handle, with prepare_cached, which makes a new one, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # cached in its place, when the one prepared is in use; one taking a list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # is prepared for the values given, and not cached. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 195 | ▶ | sub _run_statement ($definition, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_statement: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 195 | my $dbh = database($definition->{database}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 194 | my @statement = @$definition{qw(statement attrs)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 194 | my @stages = (@{ $definition->{stages} }, split_stages(\@args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 194 | my $sth = DBIx::Squirrel::db::_prepare_as( ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | $dbh, prepare_cached => @statement, 3, @args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 193 | return _execute($sth, @args, @stages); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Run what a database's function is given: nothing, for the handle; a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # statement and its bind values, for the statement handle, executed; or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # those and stages after them, for an iterator, or a sink's result. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 224 | ▶ | sub _run ($name, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 224 | my $dbh = database($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 223 | ▶ | return $dbh unless @args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 200 | my $statement = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 200 | ▶ | return _execute($statement, @args) if $statement isa 'DBI::st'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 198 | ▶ | return $dbh->iterate($statement, @args) if _ends_in_stages(\@args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 187 | my $attrs = shift_attrs(\@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 187 | my $sth = DBIx::Squirrel::db::_prepare_as( ## no critic (Subroutines::ProtectPrivateSubs) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | $dbh, prepare => $statement, $attrs, undef, @args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 185 | return _execute($sth, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # Execute a statement handle with the bind values given, and return it, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # or nothing if it couldn't be executed; or, with stages after the bind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # values, return an iterator over the results, or, if the last stage is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # sink, its result. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 380 | ▶ | sub _execute ($sth, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 380 | ▶ | return $sth->iterate(@args) if _ends_in_stages(\@args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 193 | ▶ | defined $sth->execute(@args) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 191 | return $sth; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Return true if a list of arguments ends in a stage. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 578 | ▶ | sub _ends_in_stages ($args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ends_in_stages: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 578 | ▶ | return @$args && is_stage($args->[-1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@$args && is_stage($args->[-1])
MC/DC100%2/2
@$args && is_stage($args->[-1])
@$args
is_stage($args->[-1])
Truth table100%3/3
A && B
A= @$argsB= is_stage($args->[-1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # Give a package a named function, croaking if it has one of that name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # unless it's the same. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 68 | ▶ | sub _install ($package, $name, $code) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 68 | my $have = $package->can($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 68 | ▶ | return if $have && $have == $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$have and $have == $code
MC/DC100%2/2
$have and $have == $code
$have
$have == $code
Truth table100%3/3
A and B
A= $haveB= $have == $code
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 65 | ▶ | croakf 'Expected no function of the name in %s already (%s)', $package, $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | if $have; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 62 | install_sub("${package}::$name", $code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 62 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||