blib/lib/DBIx/Squirrel/Iterator.pm

filter: Statementstmt 100% 192 / 192 Branchbran 98.6% 71 / 72 Conditioncond 86.6% 39 / 45 MC/DCmcdc 74.0% 20 / 27 Subroutinesub 100% 40 / 40 Podpod 100% 10 / 10 totaltotal 96.3% 372 / 386 CC 54 SCAR 16.8
CC
54
Cov
98%
reset
14.0
__ANON__
12.0
__ANON__
5.0
CRAP 5.4
« 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 470 ▶sub new ($class, $sth, @args) {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
45 470 ▶ croakf 'Expected a DBIx::Squirrel statement handle'
Branch: 1 branch
BranchTrueFalseTotal
unless $sth isa "DBIx::Squirrel::st" 1 469 470
46 unless $sth isa 'DBIx::Squirrel::st';
47 469 my @stages = split_stages(\@args);
48 469 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 184 ▶sub first ($self) {
Subroutine first: called CC=2 SCAR=6.9
Pod documented
91 184 _executed($self);
92 184 ▶ return undef if $self->{done}; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done"} 1 183 184
93 183 my $run = $self->{run};
94 183 ▶ my $result = DBIx::Squirrel::Context::within($self, sub { $run->first });
Subroutine __ANON__: called CC=1 SCAR=0.0
95 182 _finish($self);
96 182 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 509 ▶sub reset ($self, @args) { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
Subroutine reset: called CC=14 SCAR=26.4
Pod documented
121 509 my $sth = $self->{sth};
122 509 my $state = $sth->{private_ekorn};
123 509 my $other = $state->{Iterator};
124 croakf "Expected the statement handle's other iterator to be finished"
125 509 ▶ if $other && !$other->{done} && $other != $self;
Branch: 1 branch
BranchTrueFalseTotal
if $other and not $other->{"done"} and $other != $self 1 508 509
Condition100%6/6
$other and not $other->{"done"} and $other != $self
!ll&&!rl&&r
492161
$other and not $other->{"done"}
!ll&&!rl&&r
4573517
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 508 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 12 496 508
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 508 ▶ $self->{stages} //= [@{ $self->{stages_initial} }];
Condition100%2/2
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
l!l
50458
MC/DC100%1/1
$self->{"stages"} //= [@{$self->{"stages_initial"};}]
$self->{"stages"}
Truth table100%2/2
A
A= $self->{"stages"}
Aresult
11
00
136 508 ▶ $self->{bind_values} //= [@{ $self->{bind_values_initial} }];
Condition100%2/2
$self->{"bind_values"} //= [@{$self->{"bind_values_initial"};}]
l!l
49459
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 508 _finish($self);
139 508 ▶ if ($state->{Lists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state->{"Lists"}) 20 488 508
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 506 $state->{Iterator} = $self;
149 506 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 506 my $slice = $self->_slice;
153 506 ▶ $slice = undef if is_plain_arrayref($slice) && !@$slice;
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_plain_arrayref($slice) and not @$slice 467 39 506
Condition100%3/3
Ref::Util::XS::is_plain_arrayref($slice) and not @$slice
!ll&&!rl&&r
372467
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 506 @$self{qw(executed done ended column_names slice)}
155 = (1, 0, undef, [], $slice);
156 # The source's set-up executes the statement, as the run starts.
157 506 ▶ $self->{pipeline} //= _pipeline($self);
Condition66%2/3
$self->{"pipeline"} //= _pipeline($self)
l!l&&r!l&&!r
464600
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 506 $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 502 $self->{pull} = \&{ $self->{run} };
163 502 return $self;
164 }
165  
166 # Return the pipeline of the iterator's stages. Ekorn's run counts their
167 # results, for DBIx::Squirrel::Context's result_number, so there's no
168 # stage of ours to count them (roadmap 2026-0032).
169 460 ▶sub _pipeline ($self) {
Subroutine _pipeline: called CC=1 SCAR=0.0
170 460 return Ekorn::Pipeline->new(@{ $self->{stages} });
171 }
172  
173 # Return how the last run ended, as Ekorn's iterator says: done, stopped
174 # or died; nothing while it's going, or before one has started.
175 14 ▶sub ended ($self) {
Subroutine ended: called CC=3 SCAR=11.0
Pod documented
176 14 my $run = $self->{run};
177 14 ▶ return $run->ended if $run;
Branch: 1 branch
BranchTrueFalseTotal
if $run 5 9 14
178 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
179 }
180  
181 # Return the names of the statement's columns, as fetchrow_hashref keys
182 # them, executing the statement first if it hasn't been.
183 4 ▶sub column_names ($self) {
Subroutine column_names: called CC=2 SCAR=7.1
Pod documented
184 4 _executed($self);
185 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
186 }
187  
188  
189 76 ▶sub sth ($self) {
Subroutine sth: called CC=1 SCAR=0.0
Pod documented
190 76 return $self->{sth};
191 }
192  
193 # An iterator is a source: each run reads the statement afresh, from its
194 # first row, through the iterator's stages, passing on the statement's
195 # columns as the run's context.
196 27 ▶sub EKORN_SOURCE ($self) {
Subroutine EKORN_SOURCE: called CC=1 SCAR=0.0
Pod documented
197 27 local $self->{read_by_pipeline} = 1;
198 27 $self->reset;
199 27 return $self->{run}->EKORN_SOURCE;
200 }
201  
202 # For the calls taking stages: return the iterator; or, if its last stage
203 # is a sink, the sink's result, reading the run to its end. A sink of
204 # many, whose items a run hands out one by one, gives them as a list,
205 # or, where one value is asked for, as an array reference.
206 469 ▶sub _or_sink ($self) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _or_sink: called CC=4 SCAR=13.9
207 469 my $stages = $self->{stages_initial};
208 469 ▶ my $sink = @$stages && Ekorn::Pipeline::is_sink($stages->[-1]);
Condition100%3/3
@$stages && Ekorn::Pipeline::is_sink($stages->[-1])
!ll&&!rl&&r
104155210
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
209 469 ▶ return $self unless $sink;
Branch: 1 branch
BranchTrueFalseTotal
unless $sink 259 210 469
210 210 ▶ return $self->first unless $sink eq 'many';
Branch: 1 branch
BranchTrueFalseTotal
unless $sink eq "many" 174 36 210
211 36 return $self->all;
212 }
213  
214 # Execute the statement, unless it's been executed.
215 413 ▶sub _executed ($self) {
Subroutine _executed: called CC=2 SCAR=6.9
216 413 ▶ $self->reset unless $self->{executed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"executed"} 370 43 413
217 411 return;
218 }
219  
220 # End the run, if one is going, and finish the statement. What the run
221 # held goes with it: its batch, and anything its Ekorn iterator holds.
222 936 ▶sub _finish ($self) {
Subroutine _finish: called CC=3 SCAR=11.0
223 936 delete $self->{pull};
224 936 my $run = delete $self->{run};
225 936 ▶ if ($run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run) 444 492 936
226 444 $run->finish;
227 444 $self->{ended} = $run->ended;
228 }
229 936 $self->{done} = 1;
230 936 my $sth = $self->{sth};
231 936 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 1 935 936
232 936 return;
233 }
234  
235 # Return a source of the statement's rows, made for each run: its set-up
236 # executes the statement and reads the columns' names; its step gives the
237 # next row, from a batch of the run's own, fetched as needed, or every row
238 # left at once when all asks for them without stages; its end finishes
239 # the statement. A run's end touches only its own run, as the iterator
240 # ends a run before it starts another. The run keeps what it needs
241 # itself, so it reads on if the iterator is let go first, as when a
242 # pipeline reads it. A subclass can make something else of each row,
243 # before the stages see it, with a _row_maker method of its own, as
244 # DBIx::Squirrel::Results does.
245 506 ▶sub _statement ($self) {
Subroutine _statement: called CC=1 SCAR=0.0
246 506 weaken $self;
247 506 ▶ return source {
Subroutine __ANON__: called CC=5 SCAR=16.1
248 506 my $sth = $self->{sth};
249 506 my $slice = $self->{slice};
250 506 my @binds = @{ $self->{bind_values} };
251 # With no stages of the iterator's own, and no pipeline reading it,
252 # nothing asks which row a value came from, so a step gives the
253 # whole batch, which costs less than a row at a time.
254 506 ▶ my $whole = !@{ $self->{stages} } && !$self->{read_by_pipeline};
Condition100%3/3
@{$self->{'stages'};} || $self->{'read_by_pipeline'}
l!l&&r!l&&!r
3991691
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
255 506 my @buffer;
256 506 my $batch = $BATCH_FIRST;
257 506 my $done = !defined $sth->execute(@binds);
258 503 my @names;
259 # The names are read now, before a row is fetched: once the last
260 # row is, DBD::mysql gives none, unless they were read before.
261 503 ▶ unless ($done) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 500 3 503
262 500 ▶ my $key = $sth->{FetchHashKeyName} || 'NAME';
Condition50%1/2
$sth->{'FetchHashKeyName'} || 'NAME'
l!l
5000
MC/DC0%0/1
$sth->{'FetchHashKeyName'} || 'NAME'
$sth->{'FetchHashKeyName'}
Truth table50%1/2
A
A= $sth->{'FetchHashKeyName'}
Aresult
11
00
263 500 ▶ @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'} ? : 496 4 500
264 }
265 503 $self->{column_names} = [@names];
266 503 ▶ my $row = $done ? undef : $self->_row_maker($sth);
Branch: 1 branch
BranchTrueFalseTotal
$done ? : 3 500 503
267 # The run's context: the statement, its columns, and the row given
268 # last, which the stages behind the source are working on, for
269 # DBIx::Squirrel::Context and the stages that ask for columns.
270 502 my $context = {columns => [@names], statement => $sth, row => undef};
271 1695 ▶ my $fetch = sub ($size) {
Subroutine __ANON__: called CC=1 SCAR=0.0
272 1695 ▶ return at_caller {
Subroutine __ANON__: called CC=3 SCAR=11.1
273 $sth->{Active} && $sth->{NUM_OF_FIELDS}
274 1695 ▶ ? $sth->fetchall_arrayref($slice, $size)
Branch: 1 branch
BranchTrueFalseTotal
$sth->{'Active'} && $sth->{'NUM_OF_FIELDS'} ? : 1384 311 1695
Condition66%2/3
$sth->{"Active"} and $sth->{"NUM_OF_FIELDS"}
!ll&&!rl&&r
31101384
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
275 : undef;
276 1695 };
277 502 };
278 # Given an array of rows, it makes each in place: given every row
279 # left, by all, a list of them would be copied in and out, about
280 # 16 ns a row (roadmap 2026-0028).
281 1327 ▶ my $made = sub ($rows) {
Subroutine __ANON__: called CC=3 SCAR=11.0
282 1327 ▶ @$rows = map { $row->($_) } @$rows if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 63 1264 1327
283 1327 ▶ $context->{row} = $rows->[-1] if @$rows;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows 1323 4 1327
284 1327 return @$rows;
285 502 };
286 # Without a signature, as it's called for each row.
287 12962 ▶ my $step = sub {
Subroutine __ANON__: called CC=12 SCAR=24.9
288 # A row at a time from the batch, as stages or a pipeline read
289 # it: the commonest case, so it's done here, without a call
290 # of $made for each row.
291 12962 ▶ if (@buffer && !$whole) {
Branch: 1 branch
BranchTrueFalseTotal
if (@buffer and not $whole) 11237 1725 12962
Condition66%2/3
@buffer and not $whole
!ll&&!rl&&r
1725011237
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
292 11237 my $next = shift @buffer;
293 11237 ▶ $next = $row->($next) if $row;
Branch: 1 branch
BranchTrueFalseTotal
if $row 27 11210 11237
294 11237 return $context->{row} = $next;
295 }
296 1725 ▶ return if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 30 1695 1725
297 1695 ▶ if ($self && $self->{all_at_once}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self and $self->{"all_at_once"}) 33 1662 1695
Condition100%3/3
$self and $self->{"all_at_once"}
!ll&&!rl&&r
9165333
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
298 # The rows fetched are the run's own, so anything left of the
299 # batch goes in front of them, not they after it; without
300 # stages, a step gives a whole batch, so nothing is.
301 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
302 31 unshift @$rows, splice @buffer;
303 31 $done = 1;
304 31 return $made->($rows);
305 }
306 # The batch is used up here, as a whole batch is given at once,
307 # and a row at a time is given above while any are left.
308 1662 my $rows = $fetch->($batch);
309 1662 ▶ unless ($rows && @$rows) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows and @$rows) 366 1296 1662
Condition100%3/3
$rows and @$rows
!ll&&!rl&&r
310561296
MC/DC100%2/2
$rows and @$rows
$rows @$rows
Truth table100%3/3
A and B
A= $rowsB= @$rows
ABresult
0X0
100
111
310 366 $done = 1;
311 366 return;
312 }
313 1296 ▶ $batch = min($batch * 2, $BATCH_LIMIT) if @$rows >= $batch;
Branch: 1 branch
BranchTrueFalseTotal
if @$rows >= $batch 976 320 1296
314 1296 ▶ return $made->($rows) if $whole;
Branch: 1 branch
BranchTrueFalseTotal
if $whole 80 1216 1296
315 1216 @buffer = @$rows;
316 1216 return $made->([shift @buffer]);
317 502 };
318 501 ▶ my $end = sub ($how) {
Subroutine __ANON__: called CC=3 SCAR=11.0
319 501 @buffer = ();
320 501 $context->{row} = undef;
321 # At program exit, the database may have gone already.
322 501 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT';
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 501 501
323 501 ▶ $sth->finish if $sth->{Active};
Branch: 1 branch
BranchTrueFalseTotal
if $sth->{"Active"} 86 415 501
324 501 return;
325 502 };
326 502 return {step => $step, end => $end, context => $context};
327 506 };
328 }
329  
330 # Return what makes each row fetched into the row the stages see, or
331 # undef for the row as it is. It's called as a run starts, once the
332 # statement is executed, and before a row is fetched, so a subclass can
333 # read the columns, and the run keeps what it returns.
334 455 ▶sub _row_maker ($self, $sth) { ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
Subroutine _row_maker: called CC=1 SCAR=0.0
335 455 return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
336 }
337  
338 # Return the slice rows are fetched as: the ekorn_slice attribute, or
339 # arrays; a subclass can choose its own.
340 460 ▶sub _slice ($self) {
Subroutine _slice: called CC=2 SCAR=6.9
341 460 ▶ return $self->{sth}{private_ekorn}{Options}{ekorn_slice} // [];
Condition100%2/2
$self->{"sth"}{"private_ekorn"}{"Options"}{"ekorn_slice"} // []
l!l
41419
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
342 }
343  
344 29 1;
345 __END__
« blib/lib/DBIx/Squirrel/st.pm ↑ Summary blib/lib/DBIx/Squirrel/Sugar.pm »