RDF/Trine/Iterator/Boolean.pm

filter: Statementstmt 64.1% 34 / 53 Branchbran 33.3% 2 / 6 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 10 / 15 Podpod 100% 7 / 7 totaltotal 59.7% 55 / 92 CC 7 SCAR 9.4
CC
7
Cov
58%
as_string
6.0
construct_args
6.0
as_json
3.1
CRAP 2.6
« RDF/Trine/Iterator/Graph/Materialized.pm ↑ Summary RDF/Trine/Exporter/RDFPatch.pm »
1 # RDF::Trine::Iterator::Boolean
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine::Iterator::Boolean - Iterator class for boolean query results
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine::Iterator::Boolean version 1.019
11  
12 =head1 SYNOPSIS
13  
14 use RDF::Trine::Iterator::Boolean;
15
16 my $iterator = RDF::Trine::Iterator::Boolean->new( [1] );
17 my $bool = $iterator->get_boolean;
18 if ($bool) {
19 print "Yes.\n";
20 }
21  
22 =head1 METHODS
23  
24 Beyond the methods documented below, this class inherits methods from the
25 L<RDF::Trine::Iterator> class.
26  
27 =over 4
28  
29 =cut
30  
31 package RDF::Trine::Iterator::Boolean;
32  
33 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 68 ▶use JSON 2.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 68 ▶use base qw(RDF::Trine::Iterator);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 68 our ($VERSION);
40 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 $VERSION = '1.019';
42 }
43  
44 =item C<new ( \@results, %args )>
45  
46 =item C<new ( \&results, %args )>
47  
48 Returns a new SPARQL Result interator object. Results must be either
49 an reference to an array containing results or a CODE reference that
50 acts as an iterator, returning successive items when called, and
51 returning undef when the iterator is exhausted.
52  
53 $type should be one of: bindings, boolean, graph.
54  
55 =cut
56  
57 7 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
58 7 my $class = shift;
59 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
700
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
60 7 my %args = @_;
61
62 7 my $type = 'boolean';
63 7 return $class->SUPER::new( $stream, $type, [], %args );
64 }
65  
66 0 ▶sub _new {
Subroutine _new: not called CC=1 SCAR=6.9
67 0 my $class = shift;
68 0 my $stream = shift;
69 0 my $type = shift;
70 0 my $names = shift;
71 0 my %args = @_;
72 0 return $class->new( $stream, %args );
73 }
74  
75 =item C<is_boolean>
76  
77 Returns true if the underlying result is a boolean value.
78  
79 =cut
80  
81 3 ▶sub is_boolean {
Subroutine is_boolean: called CC=1 SCAR=0.0
Pod documented
82 3 my $self = shift;
83 3 return 1;
84 }
85  
86 =item C<as_string ( $max_size [, \$count] )>
87  
88 Returns a string serialization of the stream data.
89  
90 =cut
91  
92 0 ▶sub as_string {
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
93 0 my $self = shift;
94 0 ▶ my $value = $self->get_boolean ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$self->get_boolean ? : 0 0 0
95 0 return $value;
96 }
97  
98 =item C<as_xml ( $max_size )>
99  
100 Returns an XML serialization of the stream data.
101  
102 =cut
103  
104 1 ▶sub as_xml {
Subroutine as_xml: called CC=2 SCAR=7.0
Pod documented
105 1 my $self = shift;
106 1 ▶ my $value = $self->get_boolean ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$self->get_boolean ? : 1 0 1
107 1 my $xml = <<"END";
108 <?xml version="1.0" encoding="utf-8"?>
109 <sparql xmlns="http://www.w3.org/2005/sparql-results#">
110 <head></head>
111 <boolean>${value}</boolean>
112 </sparql>
113 END
114 1 return $xml;
115 }
116  
117 =item C<< print_xml ( $fh, $max_size ) >>
118  
119 Prints an XML serialization of the stream data to the filehandle $fh.
120  
121 =cut
122  
123 0 ▶sub print_xml {
Subroutine print_xml: not called CC=1 SCAR=6.9
Pod documented
124 0 my $self = shift;
125 0 my $fh = shift;
126 0 print {$fh} $self->as_xml;
127 }
128  
129 =item C<as_json ( $max_size )>
130  
131 Returns a JSON serialization of the stream data.
132  
133 =cut
134  
135 1 ▶sub as_json {
Subroutine as_json: called CC=3 SCAR=11.3
Pod documented
136 1 my $self = shift;
137 1 ▶ my $max_result_size = shift || 0;
Condition50%1/2
shift() || 0
l!l
01
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
138 1 ▶ my $value = $self->get_boolean ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$self->get_boolean ? : 0 1 1
139 1 my $data = { head => { vars => [] }, boolean => $value };
140 1 return to_json( $data );
141 }
142  
143 =item C<< construct_args >>
144  
145 Returns the arguments necessary to pass to the stream constructor _new
146 to re-create this stream (assuming the same closure as the first
147  
148 =cut
149  
150 0 ▶sub construct_args {
Subroutine construct_args: not called CC=2 SCAR=17.9
Pod documented
151 0 my $self = shift;
152 0 my $type = $self->type;
153 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
154 0 return ($type, [], %{ $args });
155 }
156  
157  
158 68 1;
159  
160 __END__
« RDF/Trine/Iterator/Graph/Materialized.pm ↑ Summary RDF/Trine/Exporter/RDFPatch.pm »