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/db.pm ↑ Summary blib/lib/DBIx/Squirrel/Sugar.pm »
1 28 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package DBIx::Squirrel::Iterator;
4  
5 28 ▶use experimental qw(builtin);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 28 ▶use builtin qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 28 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 28 ▶use Ref::Util qw(is_plain_arrayref);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 28 ▶use Ekorn::Pipeline qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 28 ▶use Ekorn::Pipeline::Factories qw(source);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 28 ▶use Ekorn::Pipeline::Operators qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 28 ▶use DBIx::Squirrel::Context qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 28 ▶use DBIx::Squirrel::Errors qw(at_caller croakf);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 28 ▶use DBIx::Squirrel::Util qw(split_stages);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 28 ▶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 28 ▶ '|' => \&Ekorn::Pipeline::Operators::chain,
Subroutine BEGIN: called CC=1 SCAR=0.0
27 '@{}' => \&Ekorn::Pipeline::Operators::drain,
28 28 fallback => 1;
29  
30 # Croak at the line that called DBIx::Squirrel.
31 28 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 28 my $BATCH_FIRST = 2;
40 28 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 466 ▶sub new ($class, $sth, @args) {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
45 466 ▶ croakf 'Expected a DBIx::Squirrel statement handle'
Branch: 1 branch
BranchTrueFalseTotal
unless $sth isa "DBIx::Squirrel::st" 1 465 466
46 unless $sth isa 'DBIx::Squirrel::st';
47 465 my @stages = split_stages(\@args);
48 465 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 200 ▶sub all ($self) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine all: called CC=3 SCAR=11.0
Pod documented
78 200 _executed($self);
79 198 my $all = [];
80 198 ▶ unless ($self->{done}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"done"}) 196 2 198
81 196 local $self->{all_at_once} = !@{ $self->{stages} };
82 196 my $run = $self->{run};
83 196 ▶ $all = DBIx::Squirrel::Context::within($self, sub { scalar $run->all });
Subroutine __ANON__: called CC=1 SCAR=0.0
84 182 _finish($self);
85 }
86 184 ▶ return wantarray ? @$all : $all;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 161 23 184
87 }
88  
89 # Return the next result, or undef if there's none, and finish the run.
90 182 ▶sub first ($self) {
Subroutine first: called CC=2 SCAR=6.9
Pod documented
91 182 _executed($self);
92 182 ▶ return undef if $self->{done}; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 1 181 182
93 181 my $run = $self->{run};
94 181 ▶ my $result = DBIx::Squirrel::Context::within($self, sub { $run->first });
Subroutine __ANON__: called CC=1 SCAR=0.0
95 180 _finish($self);
96 180 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 506 ▶sub reset ($self, @args) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine reset: called CC=14 SCAR=26.4
Pod documented
121 506 my $sth = $self->{sth};
122 506 my $state = $sth->{private_ekorn};
123 506 my $other = $state->{Iterator};
124 croakf "Expected the statement handle's other iterator to be finished"
125 506 ▶ if $other && !$other->{done} && $other != $self;
Branch: 1 branch
BranchTrueFalseTotal
if $other and not $other->{"done"} and $other != $self 1 505 506
Condition100%6/6
$other and not $other->{"done"} and $other != $self
!ll&&!rl&&r
489161
$other and not $other->{"done"}
!ll&&!rl&&r
4543517
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 505 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 12 493 505
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 505 ▶ $self->{stages} //= [@{ $self->{stages_initial} }];
Condition100%2/2
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
l!l
50455
MC/DC100%1/1
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
$self->{"stages"}
Truth table100%2/2
A
A= $self->{"stages"}
Aresult
11
00
136 505 ▶ $self->{bind_values} //= [@{ $self->{bind_values_initial} }];
Condition100%2/2
$self->{"bind_values"} //= [@{$self->{"bind_values_initial"};}]
l!l
49456
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 505 _finish($self);
139 505 ▶ if ($state->{Lists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"Lists"}) 20 485 505
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 503 $state->{Iterator} = $self;
149 503 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 503 my $slice = $self->_slice;
153 503 ▶ $slice = undef if is_plain_arrayref($slice) && !@$slice;
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_arrayref($slice) and not @$slice 464 39 503
Condition100%3/3
Ref::Util::XS::is_plain_arrayref($slice) and not @$slice
!ll&&!rl&&r
372464
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 503 @$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 503 ▶ $self->{pipeline} //= _pipeline($self);
Condition66%2/3
$self->{"pipeline"} //= _pipeline($self)
l!l&&r!l&&!r
464570
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 503 $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 499 $self->{pull} = \&{ $self->{run} };
163 499 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 457 ▶sub _pipeline ($self) {
Subroutine _pipeline: called CC=3 SCAR=11.0
171 457 my @counted = @{ $self->{stages} };
172 457 ▶ if (@counted) {
Branch: 1 branch
BranchTrueFalseTotal
if (@counted) 360 97 457
173 360 my $counter = $self;
174 360 weaken $counter;
175 360 ▶ my $at = Ekorn::Pipeline::is_sink($counted[-1]) ? $#counted : @counted;
Branch: 1 branch
BranchTrueFalseTotal
Ekorn::Pipeline::is_sink($counted[-1]) ? : 209 151 360
176  
177 # Without a signature, as it's called for each result.
178 360 ▶ splice @counted, $at, 0, sub { $counter->{produced}++; $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
179 }
180 457 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 75 ▶sub sth ($self) {
Subroutine sth: called CC=1 SCAR=0.0
Pod documented
200 75 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 465 ▶sub _or_sink ($self) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _or_sink: called CC=4 SCAR=13.9
217 465 my $stages = $self->{stages_initial};
218 465 ▶ my $sink = @$stages && Ekorn::Pipeline::is_sink($stages->[-1]);
Condition100%3/3
@$stages && Ekorn::Pipeline::is_sink($stages->[-1])
!ll&&!rl&&r
103153209
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 465 ▶ return $self unless $sink;
Branch: 1 branch
BranchTrueFalseTotal
unless $sink 256 209 465
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 410 ▶sub _executed ($self) {
Subroutine _executed: called CC=2 SCAR=6.9
226 410 ▶ $self->reset unless $self->{executed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"executed"} 367 43 410
227 408 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 930 ▶sub _finish ($self) {
Subroutine _finish: called CC=3 SCAR=11.0
233 930 delete $self->{pull};
234 930 my $run = delete $self->{run};
235 930 ▶ if ($run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run) 441 489 930
236 441 $run->finish;
237 441 $self->{ended} = $run->ended;
238 }
239 930 $self->{done} = 1;
240 930 my $sth = $self->{sth};
241 930 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 1 929 930
242 930 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 503 ▶sub _statement ($self) {
Subroutine _statement: called CC=1 SCAR=0.0
256 503 weaken $self;
257 503 ▶ return source {
Subroutine __ANON__: called CC=5 SCAR=16.1
258 503 my $sth = $self->{sth};
259 503 my $slice = $self->{slice};
260 503 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 503 ▶ my $whole = !@{ $self->{stages} } && !$self->{read_by_pipeline};
Condition100%3/3
@{$self->{'stages'};} || $self->{'read_by_pipeline'}
l!l&&r!l&&!r
3961691
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 503 my @buffer;
266 503 my $batch = $BATCH_FIRST;
267 503 my $done = !defined $sth->execute(@binds);
268 500 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 500 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 497 3 500
272 497 ▶ my $key = $sth->{FetchHashKeyName} || 'NAME';
Condition50%1/2
$sth->{'FetchHashKeyName'} || 'NAME'
l!l
4970
MC/DC0%0/1
$sth->{'FetchHashKeyName'} || 'NAME'
$sth->{'FetchHashKeyName'}
Truth table50%1/2
A
A= $sth->{'FetchHashKeyName'}
Aresult
11
00
273 497 ▶ @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'} ? : 493 4 497
274 }
275 500 $self->{column_names} = [@names];
276 500 ▶ my $row = $done ? undef : $self->_row_maker($sth);
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 3 497 500
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 499 my $context = {columns => [@names], statement => $sth, row => undef};
281 1689 ▶ my $fetch = sub ($size) {
Subroutine __ANON__: called CC=1 SCAR=0.0
282 1689 ▶ return at_caller {
Subroutine __ANON__: called CC=3 SCAR=11.1
283 $sth->{Active} && $sth->{NUM_OF_FIELDS}
284 1689 ▶ ? $sth->fetchall_arrayref($slice, $size)
Branch: 1 branch
BranchTrueFalseTotal
$sth->{'Active'} && $sth->{'NUM_OF_FIELDS'} ? : 1379 310 1689
Condition66%2/3
$sth->{"Active"} and $sth->{"NUM_OF_FIELDS"}
!ll&&!rl&&r
31001379
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 1689 };
287 499 };
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 1322 ▶ my $made = sub ($rows) {
Subroutine __ANON__: called CC=3 SCAR=11.0
292 1322 ▶ @$rows = map { $row->($_) } @$rows if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 63 1259 1322
293 1322 ▶ $context->{row} = $rows->[-1] if @$rows;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows 1318 4 1322
294 1322 return @$rows;
295 499 };
296 # Without a signature, as it's called for each row.
297 12954 ▶ 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 12954 ▶ if (@buffer && !$whole) {
Branch: 1 branch
BranchTrueFalseTotal
if (@buffer and not $whole) 11235 1719 12954
Condition66%2/3
@buffer and not $whole
!ll&&!rl&&r
1719011235
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 11235 my $next = shift @buffer;
303 11235 ▶ $next = $row->($next) if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 27 11208 11235
304 11235 return $context->{row} = $next;
305 }
306 1719 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 30 1689 1719
307 1689 ▶ if ($self && $self->{all_at_once}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $self->{"all_at_once"}) 33 1656 1689
Condition100%3/3
$self and $self->{"all_at_once"}
!ll&&!rl&&r
9164733
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 1656 my $rows = $fetch->($batch);
319 1656 ▶ unless ($rows && @$rows) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows and @$rows) 365 1291 1656
Condition100%3/3
$rows and @$rows
!ll&&!rl&&r
309561291
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 1291 ▶ $batch = min($batch * 2, $BATCH_LIMIT) if @$rows >= $batch;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows >= $batch 973 318 1291
324 1291 ▶ return $made->($rows) if $whole;
Branch: 1 branch
BranchTrueFalseTotal
if $whole 80 1211 1291
325 1211 @buffer = @$rows;
326 1211 return $made->([shift @buffer]);
327 499 };
328 498 ▶ my $end = sub ($how) {
Subroutine __ANON__: called CC=3 SCAR=11.0
329 498 @buffer = ();
330 498 $context->{row} = undef;
331 # At program exit, the database may have gone already.
332 498 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT';
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 498 498
333 498 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 85 413 498
334 498 return;
335 499 };
336 499 return {step => $step, end => $end, context => $context};
337 503 };
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 452 ▶sub _row_maker ($self, $sth) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _row_maker: called CC=1 SCAR=0.0
345 452 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 457 ▶sub _slice ($self) {
Subroutine _slice: called CC=2 SCAR=6.9
351 457 ▶ return $self->{sth}{private_ekorn}{Options}{ekorn_slice} // [];
Condition100%2/2
$self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"} // []
l!l
41416
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 28 1;
355 __END__
« blib/lib/DBIx/Squirrel/db.pm ↑ Summary blib/lib/DBIx/Squirrel/Sugar.pm »