Query/Expression.pm

filter: Statementstmt 61.1% 44 / 72 Branchbran 33.3% 4 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.2% 13 / 18 Podpod 100% 10 / 10 totaltotal 63.3% 71 / 112 CC 10 SCAR 21.0
CC
10
Cov
57%
nonaggregated_referenced_variables
30.0
explain
12.0
referenced_variables
4.0
CRAP 8.1
« Query/Temporal.pm ↑ Summary Query/Plan/Construct.pm »
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.919.
11  
12 =cut
13  
14 package RDF::Query::Expression;
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 36 ▶use base qw(RDF::Query::Algebra);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ######################################################################
26  
27 36 our ($VERSION);
28 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 36 $VERSION = '2.919';
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 308 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
47 308 my $class = shift;
48 308 my $op = shift;
49 308 my @operands = @_;
50 308 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 256 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
61 256 my $self = shift;
62 256 return ($self->op, $self->operands);
63 }
64  
65 =item C<< op >>
66  
67 Returns the operator of the expression.
68  
69 =cut
70  
71 1034 ▶sub op {
Subroutine op: called CC=1 SCAR=0.0
Pod documented
72 1034 my $self = shift;
73 1034 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 1388 ▶sub operands {
Subroutine operands: called CC=1 SCAR=0.0
Pod documented
83 1388 my $self = shift;
84 1388 return @{ $self }[ 1 .. $#{ $self } ];
85 }
86  
87 =item C<< sse >>
88  
89 Returns the SSE string for this algebra expression.
90  
91 =cut
92  
93 0 ▶sub sse {
Subroutine sse: not called CC=1 SCAR=6.9
Pod documented
94 0 my $self = shift;
95 0 my $context = shift;
96
97 return sprintf(
98 '(%s %s)',
99 $self->op,
100 0 join(' ', map { $_->sse( $context ) } $self->operands),
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 0 ▶sub explain {
Subroutine explain: not called CC=3 SCAR=24.8
Pod documented
113 0 my $self = shift;
114 0 my $s = shift;
115 0 my $count = shift;
116 0 my $indent = $s x $count;
117 0 my $type = $self->op;
118 0 my $string = "${indent}${type}\n";
119 0 foreach my $p ($self->operands) {
120 0 ▶ if ($p->can('explain')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->can('explain')) { } 0 0 0
121 0 $string .= $p->explain( $s, $count+1 );
122 } else {
123 0 $string .= $p->sse;
124 }
125 }
126 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 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
136 0 my $self = shift;
137 0 my $context = shift;
138 return {
139 type => 'expression',
140 operator => $self->op,
141 0 operands => [map { $_->as_hash($context) } $self->operands],
142 };
143 }
144  
145 =item C<< type >>
146  
147 Returns the type of this algebra expression.
148  
149 =cut
150  
151 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
152 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 26 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=4 SCAR=13.9
Pod documented
162 26 my $self = shift;
163 26 my @ops = $self->operands;
164 26 my @vars;
165 26 foreach my $o (@ops) {
166 40 ▶ if ($o->isa('RDF::Query::Node::Variable')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->isa('RDF::Query::Node::Variable')) { } 20 20 40
elsif ($o->isa('RDF::Query::Expression')) { } 8 12 20
167 20 push(@vars, $o->name);
168 } elsif ($o->isa('RDF::Query::Expression')) {
169 8 push(@vars, $o->referenced_variables);
170 }
171 }
172 26 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 0 ▶sub nonaggregated_referenced_variables {
Subroutine nonaggregated_referenced_variables: not called CC=5 SCAR=34.0
Pod documented
183 0 my $self = shift;
184 0 my @ops = $self->operands;
185 0 my @vars;
186 0 foreach my $o (@ops) {
187 0 ▶ if ($o->isa('RDF::Query::Node::Variable::ExpressionProxy')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o->isa('RDF::Query::Node::Variable::ExpressionProxy')) { } 0 0 0
elsif ($o->isa('RDF::Query::Node::Variable')) { } 0 0 0
elsif ($o->isa('RDF::Query::Expression')) { } 0 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 36 1;
198  
199 __END__
« Query/Temporal.pm ↑ Summary Query/Plan/Construct.pm »