blib/lib/DBIx/Squirrel/Iterator.pm

filter: Statementstmt 100% 195 / 195 Branchbran 98.6% 71 / 72 Conditioncond 86.6% 39 / 45 MC/DCmcdc 74.0% 20 / 27 Subroutinesub 100% 42 / 42 Podpod 100% 11 / 11 totaltotal 96.4% 378 / 392 CC 54 SCAR 16.7
CC
54
Cov
98%
reset
14.0
__ANON__
12.0
__ANON__
5.0
CRAP 5.3
« blib/lib/DBIx/Squirrel/st.pm ↑ Summary blib/lib/DBIx/Squirrel/Sugar.pm »
1 30 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package DBIx::Squirrel::Iterator;
4  
5 30 ▶use experimental qw(builtin);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 30 ▶use builtin qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use Ref::Util qw(is_plain_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 30 ▶use Ekorn::Pipeline qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 30 ▶use Ekorn::Pipeline::Factories qw(source);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 30 ▶use Ekorn::Pipeline::Operators qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 30 ▶use DBIx::Squirrel::Context qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 30 ▶use DBIx::Squirrel::Errors qw(at_caller croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 30 ▶use DBIx::Squirrel::Util qw(split_stages);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 30 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # | and @{} are Ekorn's, as for its own sources, in force only where the
23 # user wrote use Ekorn::Pipeline::Operators. Loading it with an empty
24 # import list defines them without putting them in force here.
25 use overload
26 30 ▶ '|' => \&Ekorn::Pipeline::Operators::chain,
Subroutine BEGIN: called CC=1 SCAR=0.0
27 '@{}' => \&Ekorn::Pipeline::Operators::drain,
28 30 fallback => 1;
29  
30 30 our $VERSION = 'v4.3.0';
31  
32 # Croak at the line that called DBIx::Squirrel.
33 30 our @CARP_NOT = @DBIx::Squirrel::Errors::INTERNAL;
34  
35 # How many rows are fetched at a time: 2 at first, the least that tells
36 # whether there's a second, doubling each time a fetch fills its batch,
37 # up to 64, as in version 1. Measured on 2026-11-14, reading 297,848
38 # narrow rows with SQLite, PostgreSQL and MySQL: a cap of 8 was 25 to
39 # 35% slower than 64, and 1024 at most 7% quicker. With rows of 1.6 KB
40 # or 24 KB, the cap made almost no difference.
41 30 my $BATCH_FIRST = 2;
42 30 my $BATCH_LIMIT = 64;
43  
44 # Return a new iterator over the rows of a statement handle, executed with
45 # the bind values given, and run through the stages given after them.
46 481 ▶sub new ($class, $sth, @args) {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
47 481 ▶ croakf 'Expected a DBIx::Squirrel statement handle'
Branch: 1 branch
BranchTrueFalseTotal
unless $sth isa "DBIx::Squirrel::st" 1 480 481
48 unless $sth isa 'DBIx::Squirrel::st';
49 480 my @stages = split_stages(\@args);
50 480 return bless {
51 sth => $sth,
52 bind_values_initial => \@args,
53 stages_initial => \@stages,
54 }, $class;
55 }
56  
57 # Return the next result, or nothing when there are no more, executing the
58 # statement first if it hasn't been.
59 #
60 # It's called for each row, so it does what Context's within and
61 # _executed do itself, without a call to each.
62 653 ▶sub next ($self) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine next: called CC=4 SCAR=13.9
Pod documented
63 653 ▶ $self->reset unless $self->{executed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"executed"} 73 580 653
64 650 ▶ return if $self->{done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 5 645 650
65 645 local $DBIx::Squirrel::Context::ITERATOR = $self;
66  
67 # A list assignment, in scalar context, counts the values given, so
68 # an undefined result counts, without an array to hold it.
69 645 ▶ (my($result) = $self->{pull}->()) or do {
Branch: 1 branch
BranchTrueFalseTotal
my($result) = $self->{"pull"}->() or do { _finish($self); return } 600 40 640
70 40 _finish($self);
71 40 return;
72 };
73 600 return $result;
74 }
75  
76 # Return the results still to come, reading the run to its end: as a
77 # list, or, asked for one value, an array reference of them. Without
78 # stages, the source gives every row left in one step.
79 211 ▶sub all ($self) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine all: called CC=3 SCAR=11.0
Pod documented
80 211 _executed($self);
81 209 my $all = [];
82 209 ▶ unless ($self->{done}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"done"}) 206 3 209
83 206 local $self->{all_at_once} = !@{ $self->{stages} };
84 206 my $run = $self->{run};
85 206 ▶ $all = DBIx::Squirrel::Context::within($self, sub { scalar $run->all });
Subroutine __ANON__: called CC=1 SCAR=0.0
86 192 _finish($self);
87 }
88 195 ▶ return wantarray ? @$all : $all;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 165 30 195
89 }
90  
91 # Return the results still to come as an array reference, in any
92 # context, so a hash constructor, an argument list or a sub's return
93 # can't flatten them, as all's list would be.
94 7 ▶sub all_arrayref ($self) {
Subroutine all_arrayref: called CC=1 SCAR=0.0
Pod documented
95 7 return scalar $self->all;
96 }
97  
98 # Return the next result, or undef if there's none, and finish the run.
99 184 ▶sub first ($self) {
Subroutine first: called CC=2 SCAR=6.9
Pod documented
100 184 _executed($self);
101 184 ▶ return undef if $self->{done}; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 1 183 184
102 183 my $run = $self->{run};
103 183 ▶ my $result = DBIx::Squirrel::Context::within($self, sub { $run->first });
Subroutine __ANON__: called CC=1 SCAR=0.0
104 182 _finish($self);
105 182 return $result;
106 }
107  
108 # Return the next result, or undef if there's none, warning if there's
109 # another, and finish the run.
110 24 ▶sub single ($self) {
Subroutine single: called CC=2 SCAR=6.9
Pod documented
111 24 _executed($self);
112 24 ▶ return undef if $self->{done}; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 1 23 24
113 23 my $run = $self->{run};
114 23 ▶ my $result = DBIx::Squirrel::Context::within($self, sub { $run->single });
Subroutine __ANON__: called CC=1 SCAR=0.0
115 23 _finish($self);
116 23 return $result;
117 }
118  
119 # Execute the statement again, ready to iterate from its first row, and
120 # return the iterator. Whatever the run before held goes with it. Bind
121 # values given replace those given before; stages given are added to
122 # those given to new. Both are kept until others are given. A statement
123 # with list placeholders is prepared again, on a new statement handle, if
124 # a list has a different number of values.
125 #
126 # It's called for each run, so it reads the statement handle's state, a
127 # tied fetch, once, and keeps its pipeline until its stages change, as
128 # each run of a pipeline has its own state (roadmap 2026-0028).
129 521 ▶sub reset ($self, @args) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine reset: called CC=14 SCAR=26.4
Pod documented
130 521 my $sth = $self->{sth};
131 521 my $state = $sth->{private_ekorn};
132 521 my $other = $state->{Iterator};
133 croakf "Expected the statement handle's other iterator to be finished"
134 521 ▶ if $other && !$other->{done} && $other != $self;
Branch: 1 branch
BranchTrueFalseTotal
if $other and not $other->{"done"} and $other != $self 1 520 521
Condition100%6/6
$other and not $other->{"done"} and $other != $self
!ll&&!rl&&r
504161
$other and not $other->{"done"}
!ll&&!rl&&r
4683617
MC/DC100%3/3
$other and not $other->{"done"} and $other != $self
$other not $other->{"done"} $other != $self
Truth table100%4/4
A and not(B) and C
A= $otherB= not $other->{"done"}C= $other != $self
ABCresult
0XX0
10X0
1100
1111
135  
136 520 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 12 508 520
137 12 my @stages = split_stages(\@args);
138 12 ▶ if (@stages) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stages) 2 10 12
139 2 $self->{stages} = [@{ $self->{stages_initial} }, @stages];
140 2 delete $self->{pipeline};
141 }
142 12 ▶ $self->{bind_values} = \@args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 11 1 12
143 }
144 520 ▶ $self->{stages} //= [@{ $self->{stages_initial} }];
Condition100%2/2
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
l!l
51469
MC/DC100%1/1
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
$self->{"stages"}
Truth table100%2/2
A
A= $self->{"stages"}
Aresult
11
00
145 520 ▶ $self->{bind_values} //= [@{ $self->{bind_values_initial} }];
Condition100%2/2
$self->{"bind_values"} //= [@{$self->{"bind_values_initial"};}]
l!l
50470
MC/DC100%1/1
$self->{"bind_values"} //= [@{$self->{"bind_values_initial"};}]
$self->{"bind_values"}
Truth table100%2/2
A
A= $self->{"bind_values"}
Aresult
11
00
146  
147 520 _finish($self);
148 520 ▶ if ($state->{Lists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"Lists"}) 20 500 520
149 my $again = DBIx::Squirrel::db::_prepare_again( ## no critic (Subroutines::ProtectPrivateSubs)
150 20 $sth->{Database}, $sth, @{ $self->{bind_values} },
151 );
152 18 ▶ if ($again != $sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($again != $sth) 3 15 18
153 3 delete $state->{Iterator};
154 3 ($sth, $state) = ($self->{sth} = $again, $again->{private_ekorn});
155 }
156 }
157 518 $state->{Iterator} = $self;
158 518 weaken $state->{Iterator};
159 # An empty array slice fetches every column, as no slice does, but the
160 # DBI takes its slower way given one, so it's given none.
161 518 my $slice = $self->_slice;
162 518 ▶ $slice = undef if is_plain_arrayref($slice) && !@$slice;
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_arrayref($slice) and not @$slice 479 39 518
Condition100%3/3
Ref::Util::XS::is_plain_arrayref($slice) and not @$slice
!ll&&!rl&&r
372479
MC/DC100%2/2
Ref::Util::XS::is_plain_arrayref($slice) and not @$slice
Ref::Util::XS::is_plain_arrayref($slice) not @$slice
Truth table100%3/3
A and not(B)
A= Ref::Util::XS::is_plain_arrayref($slice)B= not @$slice
ABresult
0X0
100
111
163 518 @$self{qw(executed done ended column_names slice)}
164 = (1, 0, undef, [], $slice);
165 # The source's set-up executes the statement, as the run starts.
166 518 ▶ $self->{pipeline} //= _pipeline($self);
Condition66%2/3
$self->{"pipeline"} //= _pipeline($self)
l!l&&r!l&&!r
474710
MC/DC0%0/2
$self->{"pipeline"} //= _pipeline($self)
$self->{"pipeline"} _pipeline($self)
Truth table66%2/3
A //= B
A= $self->{"pipeline"}B= _pipeline($self)
ABresult
1X1
011
000
167 518 $self->{run} = $self->{pipeline}->iterator(_statement($self));
168 # The run's code reference, taken once, as Ekorn's iterator suggests
169 # for a loop, so next doesn't pay its &{} overload on each call. It
170 # doesn't keep the run, which the iterator holds.
171 514 $self->{pull} = \&{ $self->{run} };
172 514 return $self;
173 }
174  
175 # Return the pipeline of the iterator's stages. Ekorn's run counts their
176 # results, for DBIx::Squirrel::Context's result_number, so there's no
177 # stage of ours to count them (roadmap 2026-0032).
178 471 ▶sub _pipeline ($self) {
Subroutine _pipeline: called CC=1 SCAR=0.0
179 471 return Ekorn::Pipeline->new(@{ $self->{stages} });
180 }
181  
182 # Return how the last run ended, as Ekorn's iterator says: done, stopped
183 # or died; nothing while it's going, or before one has started.
184 15 ▶sub ended ($self) {
Subroutine ended: called CC=3 SCAR=11.0
Pod documented
185 15 my $run = $self->{run};
186 15 ▶ return $run->ended if $run;
Branch: 1 branch
BranchTrueFalseTotal
if $run 5 10 15
187 10 ▶ return $self->{ended} // ();
Condition66%2/3
$self->{"ended"} // ()
l!l&&r!l&&!r
901
MC/DC50%1/2
$self->{"ended"} // ()
$self->{"ended"} ()
Truth table66%2/3
A // B
A= $self->{"ended"}B= ()
ABresult
1X1
011
000
188 }
189  
190 # Return the names of the statement's columns, as fetchrow_hashref keys
191 # them, executing the statement first if it hasn't been.
192 4 ▶sub column_names ($self) {
Subroutine column_names: called CC=2 SCAR=7.1
Pod documented
193 4 _executed($self);
194 4 ▶ return @{ $self->{column_names} // [] };
Condition50%1/2
$self->{"column_names"} // []
l!l
40
MC/DC0%0/1
$self->{"column_names"} // []
$self->{"column_names"}
Truth table50%1/2
A
A= $self->{"column_names"}
Aresult
11
00
195 }
196  
197  
198 77 ▶sub sth ($self) {
Subroutine sth: called CC=1 SCAR=0.0
Pod documented
199 77 return $self->{sth};
200 }
201  
202 # An iterator is a source: each run reads the statement afresh, from its
203 # first row, through the iterator's stages, passing on the statement's
204 # columns as the run's context.
205 30 ▶sub EKORN_SOURCE ($self) {
Subroutine EKORN_SOURCE: called CC=1 SCAR=0.0
Pod documented
206 30 local $self->{read_by_pipeline} = 1;
207 30 $self->reset;
208 30 return $self->{run}->EKORN_SOURCE;
209 }
210  
211 # For the calls taking stages: return the iterator; or, if its last stage
212 # is a sink, the sink's result, reading the run to its end. A sink of
213 # many, whose items a run hands out one by one, gives them as a list,
214 # or, where one value is asked for, as an array reference.
215 480 ▶sub _or_sink ($self) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _or_sink: called CC=4 SCAR=13.9
216 480 my $stages = $self->{stages_initial};
217 480 ▶ my $sink = @$stages && Ekorn::Pipeline::is_sink($stages->[-1]);
Condition100%3/3
@$stages && Ekorn::Pipeline::is_sink($stages->[-1])
!ll&&!rl&&r
109161210
MC/DC100%2/2
@$stages && Ekorn::Pipeline::is_sink($stages->[-1])
@$stages Ekorn::Pipeline::is_sink($stages->[-1])
Truth table100%3/3
A && B
A= @$stagesB= Ekorn::Pipeline::is_sink($stages->[-1])
ABresult
0X0
100
111
218 480 ▶ return $self unless $sink;
Branch: 1 branch
BranchTrueFalseTotal
unless $sink 270 210 480
219 210 ▶ return $self->first unless $sink eq 'many';
Branch: 1 branch
BranchTrueFalseTotal
unless $sink eq "many" 174 36 210
220 36 return $self->all;
221 }
222  
223 # Execute the statement, unless it's been executed.
224 423 ▶sub _executed ($self) {
Subroutine _executed: called CC=2 SCAR=6.9
225 423 ▶ $self->reset unless $self->{executed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"executed"} 377 46 423
226 421 return;
227 }
228  
229 # End the run, if one is going, and finish the statement. What the run
230 # held goes with it: its batch, and anything its Ekorn iterator holds.
231 957 ▶sub _finish ($self) {
Subroutine _finish: called CC=3 SCAR=11.0
232 957 delete $self->{pull};
233 957 my $run = delete $self->{run};
234 957 ▶ if ($run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run) 453 504 957
235 453 $run->finish;
236 453 $self->{ended} = $run->ended;
237 }
238 957 $self->{done} = 1;
239 957 my $sth = $self->{sth};
240 957 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 1 956 957
241 957 return;
242 }
243  
244 # Return a source of the statement's rows, made for each run: its set-up
245 # executes the statement and reads the columns' names; its step gives the
246 # next row, from a batch of the run's own, fetched as needed, or every row
247 # left at once when all asks for them without stages; its end finishes
248 # the statement. A run's end touches only its own run, as the iterator
249 # ends a run before it starts another. The run keeps what it needs
250 # itself, so it reads on if the iterator is let go first, as when a
251 # pipeline reads it. A subclass can make something else of each row,
252 # before the stages see it, with a _row_maker method of its own, as
253 # DBIx::Squirrel::Results does.
254 518 ▶sub _statement ($self) {
Subroutine _statement: called CC=1 SCAR=0.0
255 518 weaken $self;
256 518 ▶ return source {
Subroutine __ANON__: called CC=5 SCAR=16.1
257 518 my $sth = $self->{sth};
258 518 my $slice = $self->{slice};
259 518 my @binds = @{ $self->{bind_values} };
260 # With no stages of the iterator's own, and no pipeline reading it,
261 # nothing asks which row a value came from, so a step gives the
262 # whole batch, which costs less than a row at a time.
263 518 ▶ my $whole = !@{ $self->{stages} } && !$self->{read_by_pipeline};
Condition100%3/3
@{$self->{'stages'};} || $self->{'read_by_pipeline'}
l!l&&r!l&&!r
4051895
MC/DC100%2/2
@{$self->{'stages'};} || $self->{'read_by_pipeline'}
@{$self->{'stages'};} $self->{'read_by_pipeline'}
Truth table100%3/3
A || B
A= @{$self->{'stages'};}B= $self->{'read_by_pipeline'}
ABresult
1X1
011
000
264 518 my @buffer;
265 518 my $batch = $BATCH_FIRST;
266 518 my $done = !defined $sth->execute(@binds);
267 515 my @names;
268 # The names are read now, before a row is fetched: once the last
269 # row is, DBD::mysql gives none, unless they were read before.
270 515 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 512 3 515
271 512 ▶ my $key = $sth->{FetchHashKeyName} || 'NAME';
Condition50%1/2
$sth->{'FetchHashKeyName'} || 'NAME'
l!l
5120
MC/DC0%0/1
$sth->{'FetchHashKeyName'} || 'NAME'
$sth->{'FetchHashKeyName'}
Truth table50%1/2
A
A= $sth->{'FetchHashKeyName'}
Aresult
11
00
272 512 ▶ @names = at_caller { $sth->{NUM_OF_FIELDS} ? @{ $sth->{$key} } : () };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$sth->{'NUM_OF_FIELDS'} ? : 507 5 512
273 }
274 515 $self->{column_names} = [@names];
275 515 ▶ my $row = $done ? undef : $self->_row_maker($sth);
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 3 512 515
276 # The run's context: the statement, its columns, and the row given
277 # last, which the stages behind the source are working on, for
278 # DBIx::Squirrel::Context and the stages that ask for columns.
279 514 my $context = {columns => [@names], statement => $sth, row => undef};
280 1724 ▶ my $fetch = sub ($size) {
Subroutine __ANON__: called CC=1 SCAR=0.0
281 1724 ▶ return at_caller {
Subroutine __ANON__: called CC=3 SCAR=11.1
282 $sth->{Active} && $sth->{NUM_OF_FIELDS}
283 1724 ▶ ? $sth->fetchall_arrayref($slice, $size)
Branch: 1 branch
BranchTrueFalseTotal
$sth->{'Active'} && $sth->{'NUM_OF_FIELDS'} ? : 1405 319 1724
Condition66%2/3
$sth->{"Active"} and $sth->{"NUM_OF_FIELDS"}
!ll&&!rl&&r
31901405
MC/DC50%1/2
$sth->{"Active"} and $sth->{"NUM_OF_FIELDS"}
$sth->{"Active"} $sth->{"NUM_OF_FIELDS"}
Truth table66%2/3
A and B
A= $sth->{"Active"}B= $sth->{"NUM_OF_FIELDS"}
ABresult
0X0
100
111
284 : undef;
285 1724 };
286 514 };
287 # Given an array of rows, it makes each in place: given every row
288 # left, by all, a list of them would be copied in and out, about
289 # 16 ns a row (roadmap 2026-0028).
290 1348 ▶ my $made = sub ($rows) {
Subroutine __ANON__: called CC=3 SCAR=11.0
291 1348 ▶ @$rows = map { $row->($_) } @$rows if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 63 1285 1348
292 1348 ▶ $context->{row} = $rows->[-1] if @$rows;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows 1343 5 1348
293 1348 return @$rows;
294 514 };
295 # Without a signature, as it's called for each row.
296 13002 ▶ my $step = sub {
Subroutine __ANON__: called CC=12 SCAR=24.9
297 # A row at a time from the batch, as stages or a pipeline read
298 # it: the commonest case, so it's done here, without a call
299 # of $made for each row.
300 13002 ▶ if (@buffer && !$whole) {
Branch: 1 branch
BranchTrueFalseTotal
if (@buffer and not $whole) 11245 1757 13002
Condition66%2/3
@buffer and not $whole
!ll&&!rl&&r
1757011245
MC/DC50%1/2
@buffer and not $whole
@buffer not $whole
Truth table66%2/3
A and not(B)
A= @bufferB= not $whole
ABresult
0X0
100
111
301 11245 my $next = shift @buffer;
302 11245 ▶ $next = $row->($next) if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 27 11218 11245
303 11245 return $context->{row} = $next;
304 }
305 1757 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 33 1724 1757
306 1724 ▶ if ($self && $self->{all_at_once}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $self->{"all_at_once"}) 37 1687 1724
Condition100%3/3
$self and $self->{"all_at_once"}
!ll&&!rl&&r
9167837
MC/DC100%2/2
$self and $self->{"all_at_once"}
$self $self->{"all_at_once"}
Truth table100%3/3
A and B
A= $selfB= $self->{"all_at_once"}
ABresult
0X0
100
111
307 # The rows fetched are the run's own, so anything left of the
308 # batch goes in front of them, not they after it; without
309 # stages, a step gives a whole batch, so nothing is.
310 37 ▶ my $rows = $fetch->(undef) // [];
Condition100%2/2
&$fetch(undef) // []
l!l
332
MC/DC100%1/1
&$fetch(undef) // []
&$fetch(undef)
Truth table100%2/2
A
A= &$fetch(undef)
Aresult
11
00
311 35 unshift @$rows, splice @buffer;
312 35 $done = 1;
313 35 return $made->($rows);
314 }
315 # The batch is used up here, as a whole batch is given at once,
316 # and a row at a time is given above while any are left.
317 1687 my $rows = $fetch->($batch);
318 1687 ▶ unless ($rows && @$rows) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows and @$rows) 374 1313 1687
Condition100%3/3
$rows and @$rows
!ll&&!rl&&r
317571313
MC/DC100%2/2
$rows and @$rows
$rows @$rows
Truth table100%3/3
A and B
A= $rowsB= @$rows
ABresult
0X0
100
111
319 374 $done = 1;
320 374 return;
321 }
322 1313 ▶ $batch = min($batch * 2, $BATCH_LIMIT) if @$rows >= $batch;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows >= $batch 986 327 1313
323 1313 ▶ return $made->($rows) if $whole;
Branch: 1 branch
BranchTrueFalseTotal
if $whole 82 1231 1313
324 1231 @buffer = @$rows;
325 1231 return $made->([shift @buffer]);
326 514 };
327 513 ▶ my $end = sub ($how) {
Subroutine __ANON__: called CC=3 SCAR=11.0
328 513 @buffer = ();
329 513 $context->{row} = undef;
330 # At program exit, the database may have gone already.
331 513 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT';
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 513 513
332 513 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 86 427 513
333 513 return;
334 514 };
335 # The original of the value given last, the row, for Ekorn's
336 # result_original, which passes it through chains (roadmap
337 # 2026-0046).
338 return {
339 step => $step,
340 end => $end,
341 context => $context,
342 40 ▶ original => sub { $context->{row} },
Subroutine __ANON__: called CC=1 SCAR=0.0
343 514 };
344 518 };
345 }
346  
347 # Return what makes each row fetched into the row the stages see, or
348 # undef for the row as it is. It's called as a run starts, once the
349 # statement is executed, and before a row is fetched, so a subclass can
350 # read the columns, and the run keeps what it returns.
351 467 ▶sub _row_maker ($self, $sth) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _row_maker: called CC=1 SCAR=0.0
352 467 return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
353 }
354  
355 # Return the slice rows are fetched as: the ekorn_slice attribute, or
356 # arrays; a subclass can choose its own.
357 472 ▶sub _slice ($self) {
Subroutine _slice: called CC=2 SCAR=6.9
358 472 ▶ return $self->{sth}{private_ekorn}{Options}{ekorn_slice} // [];
Condition100%2/2
$self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"} // []
l!l
41431
MC/DC100%1/1
$self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"} // []
$self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"}
Truth table100%2/2
A
A= $self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"}
Aresult
11
00
359 }
360  
361 30 1;
362 __END__
« blib/lib/DBIx/Squirrel/st.pm ↑ Summary blib/lib/DBIx/Squirrel/Sugar.pm »