line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Query::Expression |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Expression - Class for Expr expressions |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Expression version 2.915_01. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Expression; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
193
|
use strict; |
|
36
|
|
|
|
|
75
|
|
|
36
|
|
|
|
|
932
|
|
17
|
36
|
|
|
36
|
|
184
|
use warnings; |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
964
|
|
18
|
36
|
|
|
36
|
|
176
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
83
|
|
|
36
|
|
|
|
|
1231
|
|
19
|
36
|
|
|
36
|
|
179
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
22599
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
283
|
use Data::Dumper; |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
1874
|
|
22
|
36
|
|
|
36
|
|
189
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
69
|
|
|
36
|
|
|
|
|
1718
|
|
23
|
36
|
|
|
36
|
|
185
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
70
|
|
|
36
|
|
|
|
|
2715
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
36
|
|
|
36
|
|
23603
|
$VERSION = '2.915_01'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 4 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item C<new ( $op, @operands )> |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Returns a new Expr structure. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
305
|
|
|
305
|
1
|
1029
|
my $class = shift; |
48
|
305
|
|
|
|
|
520
|
my $op = shift; |
49
|
305
|
|
|
|
|
596
|
my @operands = @_; |
50
|
305
|
|
|
|
|
1493
|
return bless( [ $op, @operands ], $class ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item C<< construct_args >> |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Returns a list of arguments that, passed to this class' constructor, |
56
|
|
|
|
|
|
|
will produce a clone of this algebra pattern. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub construct_args { |
61
|
247
|
|
|
247
|
1
|
342
|
my $self = shift; |
62
|
247
|
|
|
|
|
561
|
return ($self->op, $self->operands); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item C<< op >> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns the operator of the expression. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub op { |
72
|
1022
|
|
|
1022
|
1
|
1338
|
my $self = shift; |
73
|
1022
|
|
|
|
|
3259
|
return $self->[0]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item C<< operands >> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns a list of the operands of the expression. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub operands { |
83
|
1370
|
|
|
1370
|
1
|
1848
|
my $self = shift; |
84
|
1370
|
|
|
|
|
1801
|
return @{ $self }[ 1 .. $#{ $self } ]; |
|
1370
|
|
|
|
|
4191
|
|
|
1370
|
|
|
|
|
2488
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<< sse >> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub sse { |
94
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
95
|
0
|
|
|
|
|
0
|
my $context = shift; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return sprintf( |
98
|
|
|
|
|
|
|
'(%s %s)', |
99
|
|
|
|
|
|
|
$self->op, |
100
|
0
|
|
|
|
|
0
|
join(' ', map { $_->sse( $context ) } $self->operands), |
|
0
|
|
|
|
|
0
|
|
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item C<< explain >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns a string serialization of the expression appropriate for display on the |
107
|
|
|
|
|
|
|
command line. This method is primarily used by the C<< explain >> method of |
108
|
|
|
|
|
|
|
the subclasses of RDF::Query::Plan. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub explain { |
113
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
114
|
0
|
|
|
|
|
0
|
my $s = shift; |
115
|
0
|
|
|
|
|
0
|
my $count = shift; |
116
|
0
|
|
|
|
|
0
|
my $indent = $s x $count; |
117
|
0
|
|
|
|
|
0
|
my $type = $self->op; |
118
|
0
|
|
|
|
|
0
|
my $string = "${indent}${type}\n"; |
119
|
0
|
|
|
|
|
0
|
foreach my $p ($self->operands) { |
120
|
0
|
0
|
|
|
|
0
|
if ($p->can('explain')) { |
121
|
0
|
|
|
|
|
0
|
$string .= $p->explain( $s, $count+1 ); |
122
|
|
|
|
|
|
|
} else { |
123
|
0
|
|
|
|
|
0
|
$string .= $p->sse; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
0
|
return $string; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item C<< as_hash >> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the expression as a nested set of plain data structures (no objects). |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub as_hash { |
136
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
137
|
0
|
|
|
|
|
0
|
my $context = shift; |
138
|
|
|
|
|
|
|
return { |
139
|
|
|
|
|
|
|
type => 'expression', |
140
|
|
|
|
|
|
|
operator => $self->op, |
141
|
0
|
|
|
|
|
0
|
operands => [map { $_->as_hash($context) } $self->operands], |
|
0
|
|
|
|
|
0
|
|
142
|
|
|
|
|
|
|
}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item C<< type >> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the type of this algebra expression. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub type { |
152
|
0
|
|
|
0
|
1
|
0
|
return 'EXPR'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<< referenced_variables >> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub referenced_variables { |
162
|
20
|
|
|
20
|
1
|
29
|
my $self = shift; |
163
|
20
|
|
|
|
|
42
|
my @ops = $self->operands; |
164
|
20
|
|
|
|
|
34
|
my @vars; |
165
|
20
|
|
|
|
|
34
|
foreach my $o (@ops) { |
166
|
30
|
100
|
|
|
|
185
|
if ($o->isa('RDF::Query::Node::Variable')) { |
|
|
100
|
|
|
|
|
|
167
|
16
|
|
|
|
|
42
|
push(@vars, $o->name); |
168
|
|
|
|
|
|
|
} elsif ($o->isa('RDF::Query::Expression')) { |
169
|
6
|
|
|
|
|
19
|
push(@vars, $o->referenced_variables); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
20
|
|
|
|
|
80
|
return RDF::Query::_uniq(@vars); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item C<< nonaggregated_referenced_variables >> |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Returns a list of the variable names used in this algebra expression except |
178
|
|
|
|
|
|
|
those used as aliases for aggregate operations. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub nonaggregated_referenced_variables { |
183
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
184
|
0
|
|
|
|
|
|
my @ops = $self->operands; |
185
|
0
|
|
|
|
|
|
my @vars; |
186
|
0
|
|
|
|
|
|
foreach my $o (@ops) { |
187
|
0
|
0
|
|
|
|
|
if ($o->isa('RDF::Query::Node::Variable::ExpressionProxy')) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} elsif ($o->isa('RDF::Query::Node::Variable')) { |
189
|
0
|
|
|
|
|
|
push(@vars, $o->name); |
190
|
|
|
|
|
|
|
} elsif ($o->isa('RDF::Query::Expression')) { |
191
|
0
|
|
|
|
|
|
push(@vars, $o->nonaggregated_referenced_variables); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
0
|
|
|
|
|
|
return RDF::Query::_uniq(@vars); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=back |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 AUTHOR |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |