| 1 | 31 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package DBIx::Squirrel::Context; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use Ref::Util qw(is_plain_hashref); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use DBIx::Squirrel::Errors qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use Ekorn::Pipeline qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 31 | ▶ | use Ekorn::Pipeline::Context qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 31 | ▶ | use namespace::clean -except => 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 31 | our @EXPORT_OK = qw(iterator result_number result_original); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Croak at the line that called DBIx::Squirrel. | ||||||||||||||||||||||||||||
| 17 | 31 | our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # The iterator running the stages, set by the iterator while they run; a | ||||||||||||||||||||||||||||
| 20 | # package variable, so the iterator's next can localise it itself, | ||||||||||||||||||||||||||||
| 21 | # without a call for each row. The row a value came from is the run's, | ||||||||||||||||||||||||||||
| 22 | # in the context a statement's source gives it, so it's there in any run | ||||||||||||||||||||||||||||
| 23 | # reading a statement. | ||||||||||||||||||||||||||||
| 24 | 31 | our $ITERATOR; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # The iterator running the stage. | ||||||||||||||||||||||||||||
| 27 | 12 | ▶ | sub iterator : prototype() () { | ||||||||||||||||||||||||||
|
Subroutine
iterator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 12 | return $ITERATOR; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # The number of the result being made, from 1: Ekorn's own sub, under our | ||||||||||||||||||||||||||||
| 32 | # name, as every run counts its results (roadmap 2026-0032, D1), so a | ||||||||||||||||||||||||||||
| 33 | # stage reading it pays for one call, not two. Ekorn's has an empty | ||||||||||||||||||||||||||||
| 34 | # prototype from v0.3.12, as ours always had, so result_number + 1 adds | ||||||||||||||||||||||||||||
| 35 | # one. | ||||||||||||||||||||||||||||
| 36 | 31 | *result_number = \&Ekorn::Pipeline::Context::result_number; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # The row the result is being made from, as it was fetched; undef for a | ||||||||||||||||||||||||||||
| 39 | # result a flush is making, which comes from every row. Outside a run | ||||||||||||||||||||||||||||
| 40 | # reading a statement, Ekorn's: the value the run's source gave | ||||||||||||||||||||||||||||
| 41 | # (roadmap 2026-0032, D2). | ||||||||||||||||||||||||||||
| 42 | 34 | ▶ | sub result_original : prototype() () { | ||||||||||||||||||||||||||
|
Subroutine
result_original: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 34 | my $run = statement_context(); | |||||||||||||||||||||||||||
| 44 | 34 | ▶ | return Ekorn::Pipeline::Context::result_original() unless $run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 29 | ▶ | return Ekorn::Pipeline::ending() ? undef : $run->{row}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # For DBIx::Squirrel's stages: the context of the run, if its source is a | ||||||||||||||||||||||||||||
| 49 | # statement, with its columns and the row it gave last; otherwise undef. | ||||||||||||||||||||||||||||
| 50 | 83 | ▶ | sub statement_context : prototype() () { | ||||||||||||||||||||||||||
|
Subroutine
statement_context: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 83 | my $run = Ekorn::Pipeline::run_context(); | |||||||||||||||||||||||||||
| 52 | return is_plain_hashref($run) | ||||||||||||||||||||||||||||
| 53 | 83 | ▶ | && $run->{statement} isa 'DBIx::Squirrel::st' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
Ref::Util::XS::is_plain_hashref($run) and $run->{"statement"} isa "DBIx::Squirrel::st"
MC/DC50%1/2
Ref::Util::XS::is_plain_hashref($run) and $run->{"statement"} isa "DBIx::Squirrel::st"
Ref::Util::XS::is_plain_hashref($run)
$run->{"statement"} isa "DBIx::Squirrel::st"
Truth table66%2/3
A and B
A= Ref::Util::XS::is_plain_hashref($run)B= $run->{"statement"} isa "DBIx::Squirrel::st"
| |||||||||||||||||||||||||||||
| 54 | ? $run | ||||||||||||||||||||||||||||
| 55 | : undef; | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # For DBIx::Squirrel's iterators: run code with the iterator given as the | ||||||||||||||||||||||||||||
| 59 | # one running, and return what it returns. | ||||||||||||||||||||||||||||
| 60 | 403 | ▶ | sub within ($iterator, $code) { | ||||||||||||||||||||||||||
|
Subroutine
within: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 403 | local $ITERATOR = $iterator; | |||||||||||||||||||||||||||
| 62 | 403 | return $code->(); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 31 | 1; | |||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||