| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Query::Node |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Node - Base class for RDF Nodes |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Node version 2.916. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 METHODS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=over 4 |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package RDF::Query::Node; |
|
19
|
|
|
|
|
|
|
|
|
20
|
36
|
|
|
36
|
|
61827
|
use strict; |
|
|
36
|
|
|
|
|
72
|
|
|
|
36
|
|
|
|
|
1018
|
|
|
21
|
36
|
|
|
36
|
|
182
|
use warnings; |
|
|
36
|
|
|
|
|
69
|
|
|
|
36
|
|
|
|
|
1048
|
|
|
22
|
36
|
|
|
36
|
|
178
|
no warnings 'redefine'; |
|
|
36
|
|
|
|
|
66
|
|
|
|
36
|
|
|
|
|
1251
|
|
|
23
|
36
|
|
|
36
|
|
192
|
use Scalar::Util qw(blessed); |
|
|
36
|
|
|
|
|
67
|
|
|
|
36
|
|
|
|
|
1650
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
36
|
|
|
36
|
|
20500
|
use RDF::Query::Node::Blank; |
|
|
36
|
|
|
|
|
95
|
|
|
|
36
|
|
|
|
|
1748
|
|
|
26
|
36
|
|
|
36
|
|
22814
|
use RDF::Query::Node::Literal; |
|
|
36
|
|
|
|
|
119
|
|
|
|
36
|
|
|
|
|
1887
|
|
|
27
|
36
|
|
|
36
|
|
21474
|
use RDF::Query::Node::Resource; |
|
|
36
|
|
|
|
|
135
|
|
|
|
36
|
|
|
|
|
1830
|
|
|
28
|
36
|
|
|
36
|
|
265
|
use RDF::Query::Node::Variable; |
|
|
36
|
|
|
|
|
85
|
|
|
|
36
|
|
|
|
|
4539
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS); |
|
31
|
|
|
|
|
|
|
BEGIN { |
|
32
|
36
|
|
|
36
|
|
109
|
$VERSION = '2.916'; |
|
33
|
|
|
|
|
|
|
|
|
34
|
36
|
|
|
|
|
200
|
require Exporter; |
|
35
|
36
|
|
|
|
|
2366
|
@ISA = qw(Exporter); |
|
36
|
36
|
|
|
|
|
307
|
@EXPORT_OK = qw(iri blank literal variable); |
|
37
|
36
|
|
|
|
|
10451
|
%EXPORT_TAGS = ( 'all' => [qw(iri blank literal variable)] ); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item C<< is_variable >> |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns true if this RDF node is a variable, false otherwise. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub is_variable { |
|
47
|
1875
|
|
|
1875
|
1
|
456353
|
my $self = shift; |
|
48
|
1875
|
|
66
|
|
|
14749
|
return (blessed($self) and $self->isa('RDF::Query::Node::Variable')); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item C<< compare ( $a, $b ) >> |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns -1, 0, or 1 if $a is less than, equal to, or greater than $b, respectively, |
|
54
|
|
|
|
|
|
|
according to the SPARQL sorting rules. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub compare { |
|
59
|
|
|
|
|
|
|
my $a = shift; |
|
60
|
|
|
|
|
|
|
my $b = shift; |
|
61
|
|
|
|
|
|
|
warn 'compare'; |
|
62
|
|
|
|
|
|
|
for ($a, $b) { |
|
63
|
|
|
|
|
|
|
unless ($_->isa('RDF::Query::Node')) { |
|
64
|
|
|
|
|
|
|
$_ = RDF::Query::Node->from_trine( $_ ); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1; |
|
69
|
|
|
|
|
|
|
return $a <=> $b; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C<< from_trine ( $node ) >> |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a new RDF::Query::Node object with the same value as $node, a |
|
75
|
|
|
|
|
|
|
RDF::Trine::Node object. This essentially promotes C<< $node >> to a |
|
76
|
|
|
|
|
|
|
node object with extra functionality provided by the RDF::Query package |
|
77
|
|
|
|
|
|
|
(like SPARQL-defined ordering). |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub from_trine { |
|
82
|
1125
|
|
|
1125
|
1
|
2485
|
my $class = shift; |
|
83
|
1125
|
|
|
|
|
1579
|
my $n = shift; |
|
84
|
1125
|
50
|
|
|
|
11644
|
if ($n->isa('RDF::Trine::Node::Variable')) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Variable->new( $n->name ); |
|
86
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Literal')) { |
|
87
|
295
|
|
|
|
|
875
|
return RDF::Query::Node::Literal->new( $n->literal_value, $n->literal_value_language, $n->literal_datatype ); |
|
88
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Resource')) { |
|
89
|
378
|
|
|
|
|
1213
|
return RDF::Query::Node::Resource->new( $n->uri_value ); |
|
90
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Blank')) { |
|
91
|
94
|
|
|
|
|
309
|
return RDF::Query::Node::Blank->new( $n->blank_identifier ); |
|
92
|
|
|
|
|
|
|
} elsif ($n->isa('RDF::Trine::Node::Nil')) { |
|
93
|
358
|
|
|
|
|
1444
|
return $n; |
|
94
|
|
|
|
|
|
|
} else { |
|
95
|
36
|
|
|
36
|
|
222
|
use Data::Dumper; |
|
|
36
|
|
|
|
|
75
|
|
|
|
36
|
|
|
|
|
8004
|
|
|
96
|
0
|
|
|
|
|
0
|
Carp::confess "from_trine called with unrecognized node type:" . Dumper($n); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item C<< from_attean ( $node ) >> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Likewise, but from L<Attean>. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub from_attean { |
|
107
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
|
108
|
0
|
|
|
|
|
0
|
my $n = shift; |
|
109
|
0
|
0
|
|
|
|
0
|
if ($n->does('Attean::API::Variable')) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Variable->new( $n->value ); |
|
111
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::Literal')) { |
|
112
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Literal->new( $n->value, $n->language, $n->datatype ); |
|
113
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::IRI')) { |
|
114
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Resource->new( $n->as_string ); |
|
115
|
|
|
|
|
|
|
} elsif ($n->does('Attean::API::Blank')) { |
|
116
|
0
|
|
|
|
|
0
|
return RDF::Query::Node::Blank->new( $n->value ); |
|
117
|
|
|
|
|
|
|
} else { |
|
118
|
36
|
|
|
36
|
|
194
|
use Data::Dumper; |
|
|
36
|
|
|
|
|
91
|
|
|
|
36
|
|
|
|
|
14491
|
|
|
119
|
0
|
|
|
|
|
0
|
Carp::confess "from_attean called with unrecognized node type:" . Dumper($n); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<< explain >> |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns a string serialization of the node appropriate for display on the |
|
126
|
|
|
|
|
|
|
command line. This method is primarily used by the C<< explain >> method of |
|
127
|
|
|
|
|
|
|
the subclasses of RDF::Query::Plan. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub explain { |
|
132
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
133
|
0
|
|
|
|
|
0
|
my $s = shift; |
|
134
|
0
|
|
|
|
|
0
|
my $count = shift; |
|
135
|
0
|
|
|
|
|
0
|
my $indent = $s x $count; |
|
136
|
0
|
|
|
|
|
0
|
my $string = "${indent}" . $self->as_sparql . "\n"; |
|
137
|
0
|
|
|
|
|
0
|
return $string; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item C<< compare ( $node_a, $node_b ) >> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns -1, 0, or 1 if $node_a sorts less than, equal to, or greater than |
|
149
|
|
|
|
|
|
|
$node_b in the defined SPARQL ordering, respectively. This function may be |
|
150
|
|
|
|
|
|
|
used as the function argument to C<<sort>>. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub compare { |
|
155
|
0
|
|
|
0
|
1
|
0
|
my $a = shift; |
|
156
|
0
|
|
|
|
|
0
|
my $b = shift; |
|
157
|
0
|
|
|
|
|
0
|
warn 'compare'; |
|
158
|
0
|
|
|
|
|
0
|
for ($a, $b) { |
|
159
|
0
|
0
|
|
|
|
0
|
unless ($_->isa('RDF::Query::Node')) { |
|
160
|
0
|
|
|
|
|
0
|
$_ = RDF::Query::Node->from_trine( $_ ); |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1; |
|
165
|
0
|
|
|
|
|
0
|
return $a <=> $b; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C<< iri ( $iri ) >> |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Resource object with the given IRI value. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub iri { |
|
176
|
25
|
|
|
25
|
1
|
16209
|
my $iri = shift; |
|
177
|
25
|
|
|
|
|
166
|
return RDF::Query::Node::Resource->new( $iri ); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item C<< blank ( $id ) >> |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Blank object with the given identifier. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub blank { |
|
187
|
0
|
|
|
0
|
1
|
|
my $id = shift; |
|
188
|
0
|
|
|
|
|
|
return RDF::Query::Node::Blank->new( $id ); |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item C<< literal ( $value, $lang, $dt ) >> |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Literal object with the given value and optional |
|
194
|
|
|
|
|
|
|
language/datatype. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub literal { |
|
199
|
0
|
|
|
0
|
1
|
|
return RDF::Query::Node::Literal->new( @_ ); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item C<< variable ( $name ) >> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns a RDF::Query::Node::Variable object with the given variable name. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub variable { |
|
209
|
0
|
|
|
0
|
1
|
|
my $name = shift; |
|
210
|
0
|
|
|
|
|
|
return RDF::Query::Node::Variable->new( $name ); |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
1; |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
__END__ |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |