line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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.018 |
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
|
|
|
68
|
|
426
|
use strict; |
|
68
|
|
|
|
|
153
|
|
|
68
|
|
|
|
|
1749
|
|
34
|
68
|
|
|
68
|
|
328
|
use warnings; |
|
68
|
|
|
|
|
140
|
|
|
68
|
|
|
|
|
1666
|
|
35
|
68
|
|
|
68
|
|
328
|
no warnings 'redefine'; |
|
68
|
|
|
|
|
137
|
|
|
68
|
|
|
|
|
2025
|
|
36
|
68
|
|
|
68
|
|
339
|
use JSON 2.0; |
|
68
|
|
|
|
|
1110
|
|
|
68
|
|
|
|
|
483
|
|
37
|
|
|
|
|
|
|
|
38
|
68
|
|
|
68
|
|
7398
|
use base qw(RDF::Trine::Iterator); |
|
68
|
|
|
|
|
157
|
|
|
68
|
|
|
|
|
5931
|
|
39
|
|
|
|
|
|
|
our ($VERSION); |
40
|
|
|
|
|
|
|
BEGIN { |
41
|
68
|
|
|
68
|
|
20814
|
$VERSION = '1.018'; |
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
|
|
|
|
|
|
|
sub new { |
58
|
7
|
|
|
7
|
1
|
1778
|
my $class = shift; |
59
|
7
|
|
50
|
0
|
|
25
|
my $stream = shift || sub { undef }; |
|
0
|
|
|
|
|
0
|
|
60
|
7
|
|
|
|
|
19
|
my %args = @_; |
61
|
|
|
|
|
|
|
|
62
|
7
|
|
|
|
|
15
|
my $type = 'boolean'; |
63
|
7
|
|
|
|
|
42
|
return $class->SUPER::new( $stream, $type, [], %args ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _new { |
67
|
0
|
|
|
0
|
|
0
|
my $class = shift; |
68
|
0
|
|
|
|
|
0
|
my $stream = shift; |
69
|
0
|
|
|
|
|
0
|
my $type = shift; |
70
|
0
|
|
|
|
|
0
|
my $names = shift; |
71
|
0
|
|
|
|
|
0
|
my %args = @_; |
72
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub is_boolean { |
82
|
3
|
|
|
3
|
1
|
1627
|
my $self = shift; |
83
|
3
|
|
|
|
|
14
|
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
|
|
|
|
|
|
|
sub as_string { |
93
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
94
|
0
|
0
|
|
|
|
0
|
my $value = $self->get_boolean ? 'true' : 'false'; |
95
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub as_xml { |
105
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
106
|
1
|
50
|
|
|
|
4
|
my $value = $self->get_boolean ? 'true' : 'false'; |
107
|
1
|
|
|
|
|
4
|
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
|
|
|
|
|
3
|
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
|
|
|
|
|
|
|
sub print_xml { |
124
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
125
|
0
|
|
|
|
|
0
|
my $fh = shift; |
126
|
0
|
|
|
|
|
0
|
print {$fh} $self->as_xml; |
|
0
|
|
|
|
|
0
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item C<as_json ( $max_size )> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns a JSON serialization of the stream data. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub as_json { |
136
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
137
|
1
|
|
50
|
|
|
6
|
my $max_result_size = shift || 0; |
138
|
1
|
50
|
|
|
|
4
|
my $value = $self->get_boolean ? JSON::true : JSON::false; |
139
|
1
|
|
|
|
|
6
|
my $data = { head => { vars => [] }, boolean => $value }; |
140
|
1
|
|
|
|
|
5
|
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
|
|
|
|
|
|
|
sub construct_args { |
151
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
152
|
0
|
|
|
|
|
|
my $type = $self->type; |
153
|
0
|
|
0
|
|
|
|
my $args = $self->_args || {}; |
154
|
0
|
|
|
|
|
|
return ($type, [], %{ $args }); |
|
0
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__END__ |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<JSON|JSON> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<Scalar::Util|Scalar::Util> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 BUGS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
173
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
182
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
183
|
|
|
|
|
|
|
the same terms as Perl itself. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |