RDF/Trine/Iterator.pm

filter: Statementstmt 81.9% 231 / 282 Branchbran 65.7% 46 / 70 Conditioncond 48.2% 14 / 29 MC/DCmcdc 16.6% 3 / 18 Subroutinesub 79.6% 47 / 59 Podpod 100% 28 / 28 totaltotal 75.9% 369 / 486 CC 48 SCAR 13.6
CC
48
Cov
76%
format_node_xml
10.8
new
7.2
to_string
7.1
CRAP 3.9
« RDF/Trine/NamespaceMap.pm ↑ Summary RDF/Trine/Iterator/Bindings/Materialized.pm »
1 # RDF::Trine::Iterator
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine::Iterator - Iterator class for SPARQL query results
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine::Iterator version 1.019.
11  
12 =head1 SYNOPSIS
13  
14 use RDF::Trine::Iterator;
15 my $iterator = RDF::Trine::Iterator->new( \&data, 'bindings', \@names );
16 while (my $row = $iterator->next) {
17 my @vars = keys %$row;
18 # do something with @vars
19 }
20  
21 =head1 METHODS
22  
23 =over 4
24  
25 =cut
26  
27 package RDF::Trine::Iterator;
28  
29 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 68 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 68 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 68 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 68 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 68 ▶use Scalar::Util qw(blessed reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 68 ▶use XML::SAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 68 ▶use RDF::Trine::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 ▶use RDF::Trine::Iterator::SAXHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 68 ▶use RDF::Trine::Iterator::JSONHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 68 our ($VERSION, @ISA, @EXPORT_OK);
45 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
46 68 $VERSION = '1.019';
47
48 68 require Exporter;
49 68 @ISA = qw(Exporter);
50 68 @EXPORT_OK = qw(sgrep smap swatch);
51 0 ▶ use overload 'bool' => sub { $_[0] };
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
52 68 ▶ use overload '&{}' => sub {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
53 2 my $self = shift;
54 2 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
55 2 return $self->next;
56 2 };
57 68 };
58 }
59  
60 68 ▶use RDF::Trine::Iterator::Bindings;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 68 ▶use RDF::Trine::Iterator::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 68 ▶use RDF::Trine::Iterator::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 =item C<new ( \@results, $type, \@names, %args )>
65  
66 =item C<new ( \&results, $type, \@names, %args )>
67  
68 Returns a new SPARQL Result interator object. Results must be either
69 an reference to an array containing results or a CODE reference that
70 acts as an iterator, returning successive items when called, and
71 returning undef when the iterator is exhausted.
72  
73 $type should be one of: bindings, boolean, graph.
74  
75 =cut
76  
77 6241 ▶sub new {
Subroutine new: called CC=7 SCAR=19.7
Pod documented
78 6241 my $proto = shift;
79 6241 ▶ my $class = ref($proto) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
4461970
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
80 0 ▶ my $stream = shift || sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
shift() || sub { undef; }
l!l&&r!l&&!r
624100
MC/DC0%0/2
shift() || sub { undef; }
shift() sub { undef; }
Truth table33%1/3
A || B
A= shift()B= sub { undef; }
ABresult
1X1
011
000
81 6241 ▶ my $type = shift || 'bindings';
Condition100%2/2
shift() || 'bindings'
l!l
619843
MC/DC100%1/1
shift() || 'bindings'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
82 6241 ▶ my $names = shift || [];
Condition100%2/2
shift() || []
l!l
619843
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
83 6241 my %args = @_;
84
85 6241 ▶ if (ref($stream) and ref($stream) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $stream and ref $stream eq "ARRAY") 1003 5238 6241
Condition66%2/3
ref $stream and ref $stream eq "ARRAY"
!ll&&!rl&&r
052381003
MC/DC50%1/2
ref $stream and ref $stream eq "ARRAY"
ref $stream ref $stream eq "ARRAY"
Truth table66%2/3
A and B
A= ref $streamB= ref $stream eq "ARRAY"
ABresult
0X0
100
111
86 1003 my $array = $stream;
87 2820 ▶ $stream = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
88 2820 return shift(@$array);
89 }
90 1003 }
91
92 6241 my $open = 0;
93 6241 my $finished = 0;
94 6241 my $row;
95
96 6241 my $data = {
97 _open => 0,
98 _finished => 0,
99 _type => $type,
100 _names => $names,
101 _stream => $stream,
102 _args => \%args,
103 _count => 0,
104 _row => undef,
105 _peek => [],
106 # _source => Carp::longmess(),
107 };
108
109 6241 my $self = bless($data, $class);
110 6241 return $self;
111 }
112  
113 =item C<type>
114  
115 Returns the underlying result type (boolean, graph, bindings).
116  
117 =cut
118  
119 47 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
120 47 my $self = shift;
121 47 return $self->{_type};
122 }
123  
124 =item C<is_boolean>
125  
126 Returns true if the underlying result is a boolean value.
127  
128 =item C<is_bindings>
129  
130 Returns true if the underlying result is a set of variable bindings.
131  
132 =item C<is_graph>
133  
134 Returns true if the underlying result is an RDF graph.
135  
136 =cut
137  
138 2 ▶sub is_boolean { 0 }
Subroutine is_boolean: called CC=1 SCAR=0.0
Pod documented
139 0 ▶sub is_bindings { 0 }
Subroutine is_bindings: not called CC=1 SCAR=6.9
Pod documented
140 2 ▶sub is_graph { 0 }
Subroutine is_graph: called CC=1 SCAR=0.0
Pod documented
141  
142  
143  
144 =item C<to_string ( $format )>
145  
146 Returns a string representation of the stream data in the specified
147 C<$format>. If C<$format> is missing, defaults to XML serialization.
148 Other options are:
149  
150 http://www.w3.org/2001/sw/DataAccess/json-sparql/
151  
152 =cut
153  
154 4 ▶sub to_string {
Subroutine to_string: called CC=5 SCAR=19.6
Pod documented
155 4 my $self = shift;
156 4 ▶ my $format = shift || 'http://www.w3.org/2005/sparql-results#';
Condition50%1/2
shift() || 'http://www.w3.org/2005/sparql-results#'
l!l
04
MC/DC0%0/1
shift() || 'http://www.w3.org/2005/sparql-results#'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
157 4 ▶ if (ref($format) and $format->isa('RDF::Redland::URI')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $format and $format->isa("RDF::Redland::URI")) 0 4 4
Condition33%1/3
ref $format and $format->isa("RDF::Redland::URI")
!ll&&!rl&&r
400
MC/DC0%0/2
ref $format and $format->isa("RDF::Redland::URI")
ref $format $format->isa("RDF::Redland::URI")
Truth table33%1/3
A and B
A= ref $formatB= $format->isa("RDF::Redland::URI")
ABresult
0X0
100
111
158 0 $format = $format->as_string;
159 }
160
161 4 ▶ if ($format eq 'http://www.w3.org/2001/sw/DataAccess/json-sparql/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'http://www.w3.org/2001/sw/DataAccess/json-sparql/') { } 0 4 4
162 0 return $self->as_json;
163 } else {
164 4 return $self->as_xml;
165 }
166 }
167  
168 =item C<< from_string ( $xml ) >>
169  
170 Returns a new iterator using the supplied XML string in the SPARQL XML Results format.
171  
172 =cut
173  
174 3 ▶sub from_string {
Subroutine from_string: called CC=1 SCAR=0.0
Pod documented
175 3 my $class = shift;
176 3 my $string = shift;
177 3 my $bytes = encode('UTF-8', $string);
178 3 return $class->from_bytes($bytes);
179 }
180  
181 =item C<< from_bytes ( $xml ) >>
182  
183 Returns a new iterator using the supplied XML byte sequence (note: not character data)
184 in the SPARQL XML Results format.
185  
186 =cut
187  
188 3 ▶sub from_bytes {
Subroutine from_bytes: called CC=2 SCAR=6.9
Pod documented
189 3 my $class = shift;
190 3 my $string = shift;
191 3 ▶ unless (ref($string)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $string) 3 0 3
192 3 my $data = $string;
193 3 open( my $fh, '<', \$data );
194 3 $string = $fh;
195 }
196 3 my $handler = RDF::Trine::Iterator::SAXHandler->new();
197 3 my $p = XML::SAX::ParserFactory->parser(Handler => $handler);
198 3 $p->parse_file( $string );
199 3 my $iter = $handler->iterator;
200 3 return $iter;
201 }
202  
203 =item C<< from_json ( $json ) >>
204  
205 =cut
206  
207 0 ▶sub from_json {
Subroutine from_json: not called CC=1 SCAR=6.9
Pod documented
208 0 my $class = shift;
209 0 my $json = shift;
210 0 my $p = RDF::Trine::Iterator::JSONHandler->new( @_ );
211 0 return $p->parse( $json );
212 }
213  
214  
215 =item C<< next_result >>
216  
217 =item C<< next >>
218  
219 Returns the next item in the stream.
220  
221 =cut
222  
223 2 ▶sub next_result { $_[0]->next }
Subroutine next_result: called CC=1 SCAR=0.0
Pod documented
224 17232 ▶sub next {
Subroutine next: called CC=5 SCAR=16.1
Pod documented
225 17232 my $self = shift;
226 17232 ▶ return if ($self->{_finished});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_finished"} 19 17213 17232
227
228 17213 ▶ if (scalar(@{ $self->{_peek} })) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"_peek"};}) 13 17200 17213
229 13 return shift(@{ $self->{_peek} });
230 }
231
232 17200 my $stream = $self->{_stream};
233 17200 my $value = $stream->();
234 17200 ▶ unless (defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 6166 11034 17200
235 6166 $self->{_finished} = 1;
236 }
237  
238 17200 $self->{_open} = 1;
239 17200 $self->{_row} = $value;
240 17200 ▶ $self->{_count}++ if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 11034 6166 17200
241 17200 return $value;
242 }
243  
244 =item C<< peek >>
245  
246 Returns the next value from the iterator without consuming it. The value will
247 remain in queue until the next call to C<< next >>.
248  
249 =cut
250  
251 17 ▶sub peek {
Subroutine peek: called CC=2 SCAR=7.0
Pod documented
252 17 my $self = shift;
253 17 ▶ return if ($self->{_finished});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_finished"} 0 17 17
254 17 my $value = $self->next;
255 17 push( @{ $self->{_peek} }, $value );
256 17 return $value;
257 }
258  
259 =item C<< current >>
260  
261 Returns the current item in the stream.
262  
263 =cut
264  
265 6 ▶sub current {
Subroutine current: called CC=2 SCAR=7.6
Pod documented
266 6 my $self = shift;
267 6 ▶ if ($self->open) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->open) { } 6 0 6
268 6 return $self->_row;
269 } else {
270 0 return $self->next;
271 }
272 }
273  
274 =item C<< end >>
275  
276 =item C<< finished >>
277  
278 Returns true if the end of the stream has been reached, false otherwise.
279  
280 =cut
281  
282 0 ▶sub end { $_[0]->finished }
Subroutine end: not called CC=1 SCAR=6.9
Pod documented
283 9 ▶sub finished {
Subroutine finished: called CC=2 SCAR=6.9
Pod documented
284 9 my $self = shift;
285 9 my $v = $self->peek;
286 9 ▶ return 0 if (defined($v));
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 6 3 9
287 3 return $self->{_finished};
288 }
289  
290 =item C<< open >>
291  
292 Returns true if the first element of the stream has been retrieved, false otherwise.
293  
294 =cut
295  
296 14 ▶sub open {
Subroutine open: called CC=1 SCAR=0.0
Pod documented
297 14 my $self = shift;
298 14 return $self->{_open};
299 }
300  
301 =item C<< close >>
302  
303 Closes the stream. Future attempts to retrieve data from the stream will act as
304 if the stream had been exhausted.
305  
306 =cut
307  
308 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
309 0 my $self = shift;
310 0 $self->{_finished} = 1;
311 0 undef( $self->{ _stream } );
312 0 return;
313 }
314  
315 =item C<< concat ( $stream ) >>
316  
317 Returns a new stream resulting from the concatenation of the referant and the
318 argument streams. The new stream uses the stream type, and optional binding
319 names and C<<%args>> from the referant stream.
320  
321 =cut
322  
323 7 ▶sub concat {
Subroutine concat: called CC=1 SCAR=0.0
Pod documented
324 7 my $self = shift;
325 7 my $stream = shift;
326 7 my @args = $stream->construct_args();
327 7 my $class = ref($self);
328 7 my @streams = ($self, $stream);
329 22 ▶ my $next = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
330 22 ▶ while (@streams) {
Branch: 1 branch
BranchTrueFalseTotal
if (@streams) 29 7 36
331 29 my $data = $streams[0]->next;
332 29 ▶ unless (defined($data)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 14 15 29
333 14 shift(@streams);
334 14 next;
335 }
336 15 return $data;
337 }
338 7 return;
339 7 };
340 7 my $s = $stream->_new( $next, @args );
341 7 return $s;
342 }
343  
344 =item C<< seen_count >>
345  
346 Returns the count of elements that have been returned by this iterator at the
347 point of invocation.
348  
349 =cut
350  
351 0 ▶sub seen_count {
Subroutine seen_count: not called CC=1 SCAR=6.9
Pod documented
352 0 my $self = shift;
353 0 return $self->{_count};
354 }
355  
356 =item C<get_boolean>
357  
358 Returns the boolean value of the first item in the stream.
359  
360 =cut
361  
362 7 ▶sub get_boolean {
Subroutine get_boolean: called CC=1 SCAR=0.0
Pod documented
363 7 my $self = shift;
364 7 my $data = $self->next;
365 7 return +$data;
366 }
367  
368 =item C<get_all>
369  
370 Returns an array containing all the items in the stream.
371  
372 =cut
373  
374 953 ▶sub get_all {
Subroutine get_all: called CC=2 SCAR=6.9
Pod documented
375 953 my $self = shift;
376
377 953 my @data;
378 953 ▶ while (my $data = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->next) 1793 953 2746
379 1793 push(@data, $data);
380 }
381 953 return @data;
382 }
383  
384 =begin private
385  
386 =item C<format_node_xml ( $node, $name )>
387  
388 Returns a string representation of C<$node> for use in an XML serialization.
389  
390 =end private
391  
392 =cut
393  
394 6 ▶sub format_node_xml {
Subroutine format_node_xml: called CC=7 SCAR=23.8
Pod documented
395 6 my $self = shift;
396 # my $bridge = shift;
397 # return unless ($bridge);
398
399 6 my $node = shift;
400 6 my $name = shift;
401 6 my $node_label;
402
403 6 ▶ if (!defined $node) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $node) { } 0 6 6
elsif ($node->is_resource) { } 2 4 6
elsif ($node->isa('RDF::Trine::Node::Literal')) { } 4 0 4
elsif ($node->isa('RDF::Trine::Node::Blank')) { } 0 0 0
404 0 return '';
405 } elsif ($node->is_resource) {
406 2 $node_label = $node->uri_value;
407 2 $node_label =~ s/&/&amp;/g;
408 2 $node_label =~ s/</&lt;/g;
409 2 $node_label =~ s/"/&quot;/g;
410 2 $node_label = qq(<uri>${node_label}</uri>);
411 } elsif ($node->isa('RDF::Trine::Node::Literal')) {
412 4 $node_label = $node->literal_value;
413 4 $node_label =~ s/&/&amp;/g;
414 4 $node_label =~ s/</&lt;/g;
415 4 $node_label =~ s/"/&quot;/g;
416 4 ▶ if ($node->has_language) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->has_language) { } 0 4 4
elsif ($node->has_datatype) { } 0 4 4
417 0 my $lang = $node->literal_value_language;
418 0 $node_label = qq(<literal xml:lang="${lang}">${node_label}</literal>);
419 } elsif ($node->has_datatype) {
420 0 my $dt = $node->literal_datatype;
421 0 $node_label = qq(<literal datatype="${dt}">${node_label}</literal>);
422 } else {
423 4 $node_label = qq(<literal>${node_label}</literal>);
424 }
425 } elsif ($node->isa('RDF::Trine::Node::Blank')) {
426 0 $node_label = $node->blank_identifier;
427 0 $node_label =~ s/&/&amp;/g;
428 0 $node_label =~ s/</&lt;/g;
429 0 $node_label =~ s/"/&quot;/g;
430 0 $node_label = qq(<bnode>${node_label}</bnode>);
431 } else {
432 0 $node_label = "<unbound/>";
433 }
434 6 return qq(<binding name="${name}">${node_label}</binding>);
435 }
436  
437 =item C<< construct_args >>
438  
439 Returns the arguments necessary to pass to a stream constructor
440 to re-create this stream (assuming the same closure as the first
441 argument).
442  
443 =cut
444  
445 0 ▶sub construct_args {
Subroutine construct_args: not called CC=2 SCAR=17.9
Pod documented
446 0 my $self = shift;
447 0 my $type = $self->type;
448 0 ▶ my $args = $self->_args || {};
Condition0%0/2
$self->_args || {}
l!l
00
MC/DC0%0/1
$self->_args || {}
$self->_args
Truth table0%0/2
A
A= $self->_args
Aresult
11
00
449 0 return ($type, [], %$args);
450 }
451  
452 =item C<< each ( \&callback ) >>
453  
454 Calls the callback function once for each item in the iterator, passing the
455 item as an argument to the function. Any arguments to C<< each >> beyond the
456 callback function will be passed as supplemental arguments to the callback
457 function.
458  
459 =cut
460  
461 0 ▶sub each {
Subroutine each: not called CC=2 SCAR=17.9
Pod documented
462 0 my ($self, $coderef) = (shift, shift);
463 0 ▶ while (my $row = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->next) 0 0 0
464 0 $coderef->($row, @_);
465 }
466 }
467  
468 =begin private
469  
470 =item C<< debug >>
471  
472 Prints debugging information about the stream.
473  
474 =end private
475  
476 =cut
477  
478 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=6.9
Pod documented
479 0 my $self = shift;
480 0 my $stream = $self->{_stream};
481 0 RDF::Query::_debug_closure( $stream );
482 }
483  
484 60 ▶sub _args {
Subroutine _args: called CC=1 SCAR=0.0
485 60 my $self = shift;
486 60 return $self->{_args};
487 }
488  
489 6 ▶sub _row {
Subroutine _row: called CC=1 SCAR=0.0
490 6 my $self = shift;
491 6 return $self->{_row};
492 }
493  
494 0 ▶sub _names {
Subroutine _names: not called CC=1 SCAR=6.9
495 0 my $self = shift;
496 0 return $self->{_names};
497 }
498  
499 0 ▶sub _stream {
Subroutine _stream: not called CC=1 SCAR=6.9
500 0 my $self = shift;
501 0 return $self->{_stream};
502 }
503  
504  
505 =back
506  
507 =head1 FUNCTIONS
508  
509 =over 4
510  
511 =item C<sgrep { COND } $stream>
512  
513 =cut
514  
515 32 ▶sub sgrep (&$) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine sgrep: called CC=3 SCAR=11.2
Pod documented
516 32 my $block = shift;
517 32 my $stream = shift;
518 32 my @args = $stream->construct_args();
519 32 my $class = ref($stream);
520
521 32 my $open = 1;
522 32 my $next;
523
524 135 ▶ $next = sub {
Subroutine __ANON__: called CC=6 SCAR=18.8
525 135 ▶ return unless ($open);
Branch: 1 branch
BranchTrueFalseTotal
unless $open 0 135 135
526 135 my $data = $stream->next;
527 135 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 30 105 135
528 30 $open = 0;
529 30 return;
530 }
531
532 105 local($_) = $data;
533 105 my $bool = $block->( $data );
534 105 ▶ if ($bool) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bool) { } 59 46 105
535 # warn "[SGREP] TRUE with: " . $data->as_string;
536 59 ▶ if (@_ and $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) 0 59 59
Condition33%1/3
@_ and $_[0]
!ll&&!rl&&r
5900
MC/DC0%0/2
@_ and $_[0]
@_ $_[0]
Truth table33%1/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
537 0 $stream->close;
538 0 $open = 0;
539 }
540 59 return $data;
541 } else {
542 # warn "[SGREP] FALSE with: " . $data->as_string;
543 46 goto &$next;
544 }
545 32 };
546
547 32 ▶ Carp::confess "not a stream: " . Dumper($stream) unless (blessed($stream));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($stream) 0 32 32
548 32 ▶ Carp::confess unless ($stream->can('_new'));
Branch: 1 branch
BranchTrueFalseTotal
unless $stream->can("_new") 0 32 32
549 32 my $s = $stream->_new( $next, @args );
550 32 return $s;
551 }
552  
553 =item C<smap { EXPR } $stream>
554  
555 =cut
556  
557 1 ▶sub smap (&$;$$$) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine smap: called CC=4 SCAR=15.2
Pod documented
558 1 my $block = shift;
559 1 my $stream = shift;
560 1 my @args = $stream->construct_args();
561 1 foreach my $i (0 .. $#args) {
562 1 ▶ last unless (scalar(@_));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 1 0 1
563 0 my $new = shift;
564 0 ▶ if (defined($new)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 0 0 0
565 0 $args[ $i ] = $new;
566 }
567 }
568 1 my $class = ref($stream);
569
570 1 my $open = 1;
571 4 ▶ my $next = sub {
Subroutine __ANON__: called CC=5 SCAR=17.4
572 4 ▶ return unless ($open);
Branch: 1 branch
BranchTrueFalseTotal
unless $open 0 4 4
573 4 ▶ if (@_ and $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) 0 4 4
Condition33%1/3
@_ and $_[0]
!ll&&!rl&&r
400
MC/DC0%0/2
@_ and $_[0]
@_ $_[0]
Truth table33%1/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
574 0 $stream->close;
575 0 $open = 0;
576 }
577 4 my $data = $stream->next;
578 4 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 1 3 4
579 1 $open = 0;
580 1 return;
581 }
582
583 3 local($_) = $data;
584 3 my ($item) = $block->( $data );
585 3 return $item;
586 1 };
587
588 1 return $stream->_new( $next, @args );
589 }
590  
591 =item C<swatch { EXPR } $stream>
592  
593 =cut
594  
595 1 ▶sub swatch (&$) { ## no critic (ProhibitSubroutinePrototypes)
Subroutine swatch: called CC=1 SCAR=0.1
Pod documented
596 1 my $block = shift;
597 1 my $stream = shift;
598 1 my @args = $stream->construct_args();
599 1 my $class = ref($stream);
600
601 1 my $open = 1;
602 2 ▶ my $next = sub {
Subroutine __ANON__: called CC=5 SCAR=17.4
603 2 ▶ return unless ($open);
Branch: 1 branch
BranchTrueFalseTotal
unless $open 0 2 2
604 2 ▶ if (@_ and $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0]) 0 2 2
Condition33%1/3
@_ and $_[0]
!ll&&!rl&&r
200
MC/DC0%0/2
@_ and $_[0]
@_ $_[0]
Truth table33%1/3
A and B
A= @_B= $_[0]
ABresult
0X0
100
111
605 0 $stream->close;
606 0 $open = 0;
607 }
608 2 my $data = $stream->next;
609 2 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 1 1 2
610 1 $open = 0;
611 1 return;
612 }
613
614 1 local($_) = $data;
615 1 $block->( $data );
616 1 return $data;
617 1 };
618
619 1 my $s = $stream->_new( $next, @args );
620 1 return $s;
621 }
622  
623 68 1;
624  
625 __END__
« RDF/Trine/NamespaceMap.pm ↑ Summary RDF/Trine/Iterator/Bindings/Materialized.pm »