blib/lib/DBIx/Squirrel/Iterator.pm

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