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.916. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Expression; |
15
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
197
|
use strict; |
|
36
|
|
|
|
|
74
|
|
|
36
|
|
|
|
|
930
|
|
17
|
36
|
|
|
36
|
|
194
|
use warnings; |
|
36
|
|
|
|
|
67
|
|
|
36
|
|
|
|
|
990
|
|
18
|
36
|
|
|
36
|
|
174
|
no warnings 'redefine'; |
|
36
|
|
|
|
|
76
|
|
|
36
|
|
|
|
|
1261
|
|
19
|
36
|
|
|
36
|
|
189
|
use base qw(RDF::Query::Algebra); |
|
36
|
|
|
|
|
78
|
|
|
36
|
|
|
|
|
22919
|
|
20
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
226
|
use Data::Dumper; |
|
36
|
|
|
|
|
76
|
|
|
36
|
|
|
|
|
1854
|
|
22
|
36
|
|
|
36
|
|
189
|
use Scalar::Util qw(blessed); |
|
36
|
|
|
|
|
71
|
|
|
36
|
|
|
|
|
1941
|
|
23
|
36
|
|
|
36
|
|
196
|
use Carp qw(carp croak confess); |
|
36
|
|
|
|
|
68
|
|
|
36
|
|
|
|
|
2835
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
28
|
|
|
|
|
|
|
BEGIN { |
29
|
36
|
|
|
36
|
|
24168
|
$VERSION = '2.916'; |
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
|
1064
|
my $class = shift; |
48
|
305
|
|
|
|
|
491
|
my $op = shift; |
49
|
305
|
|
|
|
|
613
|
my @operands = @_; |
50
|
305
|
|
|
|
|
1496
|
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
|
345
|
my $self = shift; |
62
|
247
|
|
|
|
|
636
|
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
|
1030
|
|
|
1030
|
1
|
1406
|
my $self = shift; |
73
|
1030
|
|
|
|
|
3321
|
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
|
1378
|
|
|
1378
|
1
|
1910
|
my $self = shift; |
84
|
1378
|
|
|
|
|
1860
|
return @{ $self }[ 1 .. $#{ $self } ]; |
|
1378
|
|
|
|
|
4367
|
|
|
1378
|
|
|
|
|
2646
|
|
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
|
25
|
my $self = shift; |
163
|
20
|
|
|
|
|
44
|
my @ops = $self->operands; |
164
|
20
|
|
|
|
|
29
|
my @vars; |
165
|
20
|
|
|
|
|
36
|
foreach my $o (@ops) { |
166
|
30
|
100
|
|
|
|
186
|
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
|
|
|
|
|
76
|
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 |