Query/Parser.pm

filter: Statementstmt 87.3% 97 / 111 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 89.2% 25 / 28 Podpod 100% 14 / 14 totaltotal 87.2% 144 / 165 CC 7 SCAR 4.2
CC
7
Cov
85%
new_blank
3.0
new_variable
2.1
error
2.1
CRAP 1.5
« Query/Algebra/Distinct.pm ↑ Summary Query/Algebra/Optional.pm »
1 # RDF::Query::Parser
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Parser - Parser base class
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Parser version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Parser;
15  
16 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 36 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 36 ▶use RDF::Query::Node::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 36 ▶use RDF::Query::Node::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use RDF::Query::Node::Blank;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use RDF::Query::Node::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 36 ▶use RDF::Query::Algebra;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 36 ▶use RDF::Query::Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 ######################################################################
32  
33 36 our ($VERSION);
34 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 36 $VERSION = '2.919';
36 }
37  
38 ######################################################################
39  
40 =head1 METHODS
41  
42 =over 4
43  
44 =cut
45  
46 =item C<new_literal ( $literal, $language, $datatype )>
47  
48 Returns a new literal structure.
49  
50 =cut
51  
52 10 ▶sub new_literal {
Subroutine new_literal: called CC=1 SCAR=0.0
Pod documented
53 10 my $self = shift;
54 10 my $literal = shift;
55 10 my $lang = shift;
56 10 my $dt = shift;
57 10 return RDF::Query::Node::Literal->new( $literal, $lang, $dt );
58 }
59  
60 =item C<new_variable ( $name )>
61  
62 Returns a new variable structure.
63  
64 =cut
65  
66 103 ▶sub new_variable {
Subroutine new_variable: called CC=2 SCAR=7.6
Pod documented
67 103 my $self = shift;
68 103 my $name;
69 103 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 103 0 103
70 103 $name = shift;
71 } else {
72 0 my $count = $self->{__PRIVATE_VARIABLE_COUNT}++;
73 0 $name = '_____rdfquery_private_' . $count;
74 }
75 103 return RDF::Query::Node::Variable->new( $name );
76 }
77  
78 =item C<new_blank ( $name )>
79  
80 Returns a new blank node structure.
81  
82 =cut
83  
84 36 ▶sub new_blank {
Subroutine new_blank: called CC=3 SCAR=11.1
Pod documented
85 36 my $self = shift;
86 36 my $id;
87 36 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 7 29 36
88 7 $id = shift;
89 } else {
90 29 ▶ if (not defined($self->{blank_ids})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"blank_ids"}) 0 29 29
91 0 $self->{blank_ids} = 1;
92 }
93 29 $id = 'a' . $self->{blank_ids}++;
94 }
95 36 return RDF::Query::Node::Blank->new( $id );
96 }
97  
98 =item C<new_uri ( $uri )>
99  
100 Returns a new variable structure.
101  
102 =cut
103  
104 8 ▶sub new_uri {
Subroutine new_uri: called CC=1 SCAR=0.0
Pod documented
105 8 my $self = shift;
106 8 my $uri = shift;
107 8 return RDF::Query::Node::Resource->new( $uri );
108 }
109  
110 # =item C<new_qname ( $prefix, $localPart )>
111 #
112 # Returns a new QName URI structure.
113 #
114 # =cut
115 #
116 # sub new_qname {
117 # my $self = shift;
118 # my $prefix = shift;
119 # my $name = shift;
120 # return [ 'URI', [ $prefix, $name ] ];
121 # }
122 #
123 # =item C<new_union ( @patterns )>
124 #
125 # Returns a new UNION structure.
126 #
127 # =cut
128 #
129 # sub new_union {
130 # my $self = shift;
131 # my @patterns = @_;
132 # return RDF::Query::Algebra::Union->new( @patterns );
133 # }
134 #
135 # =item C<new_optional ( $patterns )>
136 #
137 # Returns a new OPTIONAL structure.
138 #
139 # =cut
140 #
141 # sub new_optional {
142 # my $self = shift;
143 # my $ggp = shift;
144 # my $opt = shift;
145 # return RDF::Query::Algebra::Optional->new( $ggp, $opt );
146 # }
147 #
148 # =item C<new_named_graph ( $graph, $triples )>
149 #
150 # Returns a new NAMED GRAPH structure.
151 #
152 # =cut
153 #
154 # sub new_named_graph {
155 # my $self = shift;
156 # my $graph = shift;
157 # my $triples = shift;
158 # return RDF::Query::Algebra::NamedGraph->new( $graph, $triples );
159 # }
160  
161 =item C<new_triple ( $s, $p, $o )>
162  
163 Returns a new triple structure.
164  
165 =cut
166  
167 0 ▶sub new_triple {
Subroutine new_triple: not called CC=1 SCAR=6.9
Pod documented
168 0 my $self = shift;
169 0 my ($s,$p,$o) = @_;
170 0 return RDF::Query::Algebra::Triple->new( $s, $p, $o );
171 }
172  
173 =item C<new_unary_expression ( $operator, $operand )>
174  
175 Returns a new unary expression structure.
176  
177 =cut
178  
179 4 ▶sub new_unary_expression {
Subroutine new_unary_expression: called CC=1 SCAR=0.0
Pod documented
180 4 my $self = shift;
181 4 my $op = shift;
182 4 my $operand = shift;
183 4 return RDF::Query::Expression::Unary->new( $op, $operand );
184 }
185  
186 =item C<new_binary_expression ( $operator, @operands )>
187  
188 Returns a new binary expression structure.
189  
190 =cut
191  
192 30 ▶sub new_binary_expression {
Subroutine new_binary_expression: called CC=1 SCAR=0.0
Pod documented
193 30 my $self = shift;
194 30 my $op = shift;
195 30 my @operands = @_[0,1];
196 30 return RDF::Query::Expression::Binary->new( $op, @operands );
197 }
198  
199 # =item C<new_nary_expression ( $operator, @operands )>
200 #
201 # Returns a new n-ary expression structure.
202 #
203 # =cut
204 #
205 # sub new_nary_expression {
206 # my $self = shift;
207 # my $op = shift;
208 # my @operands = @_;
209 # return RDF::Query::Expression::Binary->new( $op, @operands );
210 # }
211 #
212 # =item C<new_logical_expression ( $operator, @operands )>
213 #
214 # Returns a new logical expression structure.
215 #
216 # =cut
217 #
218 # sub new_logical_expression {
219 # my $self = shift;
220 # my $op = shift;
221 # my @operands = @_;
222 # die $op;
223 # return RDF::Query::Expression->new( $op, @operands );
224 # }
225  
226 =item C<new_function_expression ( $function, @operands )>
227  
228 Returns a new function expression structure.
229  
230 =cut
231  
232 67 ▶sub new_function_expression {
Subroutine new_function_expression: called CC=2 SCAR=6.9
Pod documented
233 67 my $self = shift;
234 67 my $function = shift;
235 67 my @operands = @_;
236 67 ▶ unless (blessed($function)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($function)) 7 60 67
237 7 $function = RDF::Query::Node::Resource->new( $function );
238 }
239 67 return RDF::Query::Expression::Function->new( $function, @operands );
240 }
241  
242 =item C<new_alias_expression ( $alias, $expression )>
243  
244 Returns a new alias expression structure.
245  
246 =cut
247  
248 29 ▶sub new_alias_expression {
Subroutine new_alias_expression: called CC=1 SCAR=0.0
Pod documented
249 29 my $self = shift;
250 29 my $var = shift;
251 29 my $expr = shift;
252 29 return RDF::Query::Expression::Alias->new( 'alias', $var, $expr );
253 }
254  
255 =item C<new_filter ( $filter_expr, $pattern )>
256  
257 Returns a new filter structure.
258  
259 =cut
260  
261 0 ▶sub new_filter {
Subroutine new_filter: not called CC=1 SCAR=6.9
Pod documented
262 0 my $self = shift;
263 0 my $expr = shift;
264 0 my $pattern = shift;
265 0 return RDF::Query::Algebra::Filter->new( $expr, $pattern );
266 }
267  
268  
269 ######################################################################
270  
271 =item C<fail ( $error )>
272  
273 Sets the current error to C<$error>.
274  
275 If the parser is in commit mode (by calling C<set_commit>), throws a
276 RDF::Query::Error::ParseError object. Otherwise returns C<undef>.
277  
278 =cut
279  
280 1 ▶sub fail {
Subroutine fail: called CC=2 SCAR=7.0
Pod documented
281 1 my $self = shift;
282 1 my $error = shift;
283 1 my $l = Log::Log4perl->get_logger("rdf.query.parser");
284
285 36 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
286 1 my $parsed = substr($self->{input}, 0, $self->{position});
287 1 my $line = ($parsed =~ tr/\n//) + 1;
288 1 my ($lline) = $parsed =~ m/^(.*)\Z/mx;
289 1 my $col = length($lline);
290 1 my $rest = substr($self->{remaining}, 0, 10);
291
292 1 $self->set_error( "Syntax error; $error at $line:$col (near '$rest')" );
293 1 ▶ if ($self->{commit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'commit'}) { } 0 1 1
294 0 throw RDF::Query::Error::ParseError( -text => "$error at $line:$col (near '$rest')" );
295 } else {
296 1 return undef;
297 }
298 }
299  
300 ######################################################################
301  
302 =item C<error ()>
303  
304 Returns the last error the parser experienced.
305  
306 =cut
307  
308 2 ▶sub error {
Subroutine error: called CC=2 SCAR=7.6
Pod documented
309 2 my $self = shift;
310 2 ▶ if (defined $self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'error'}) { } 2 0 2
311 2 return $self->{error};
312 } else {
313 0 return '';
314 }
315 }
316  
317 =begin private
318  
319 =item C<set_error ( $error )>
320  
321 Sets the object's error variable.
322  
323 =end private
324  
325 =cut
326  
327 1 ▶sub set_error {
Subroutine set_error: called CC=1 SCAR=0.0
Pod documented
328 1 my $self = shift;
329 1 my $error = shift;
330 1 $self->{error} = $error;
331 }
332  
333 =begin private
334  
335 =item C<clear_error ()>
336  
337 Clears the object's error variable.
338  
339 =end private
340  
341 =cut
342  
343 0 ▶sub clear_error {
Subroutine clear_error: not called CC=1 SCAR=6.9
Pod documented
344 0 my $self = shift;
345 0 $self->{error} = undef;
346 }
347  
348 # =begin private
349 #
350 # =item C<set_commit ( [ $value ] )>
351 #
352 # Sets the object's commit state.
353 #
354 # =end private
355 #
356 # =cut
357 #
358 # sub set_commit {
359 # my $self = shift;
360 # if (@_) {
361 # $self->{commit} = shift;
362 # } else {
363 # $self->{commit} = 1;
364 # }
365 # }
366 #
367 # =begin private
368 #
369 # =item C<unset_commit ()>
370 #
371 # Clears the object's commit state.
372 #
373 # =end private
374 #
375 # =cut
376 #
377 # sub unset_commit {
378 # my $self = shift;
379 # $self->{commit} = 0;
380 # }
381 #
382 # =begin private
383 #
384 # =item C<get_commit ()>
385 #
386 # Returns the object's commit state.
387 #
388 # =end private
389 #
390 # =cut
391 #
392 # sub get_commit {
393 # my $self = shift;
394 # return $self->{commit};
395 # }
396  
397 36 1;
398  
399 __END__
« Query/Algebra/Distinct.pm ↑ Summary Query/Algebra/Optional.pm »