Attean/API/Expression.pm

filter: Statementstmt 65.0% 80 / 123 Branchbran 12.5% 1 / 8 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 65.3% 17 / 26 Podpod 0.0% 0 / 13 totaltotal 56.2% 99 / 176 CC 8 SCAR 15.5
CC
8
Cov
61%
__ANON__
20.0
sparql_tokens
12.0
sparql_tokens
3.0
CRAP 4.7
« AtteanX/API/JoinRotatingPlanner.pm ↑ Summary Attean/TripleModel.pm »
1 50 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Attean::API::Expression - SPARQL expressions
7  
8 =head1 VERSION
9  
10 This document describes Attean::API::Expression version 0.040
11  
12 =head1 DESCRIPTION
13  
14 The Attean::API::Expression role defines a common API for SPARQL expressions
15 consisting of logical, numeric, and function operators, constant terms, and
16 variables. Expressions may be evaluated in the context of a
17 L<Attean::API::Result> object, and either return a L<Attean::API::Term> object
18 or throw a type error exception.
19  
20 =head1 ROLES
21  
22 This role consumes the L<Attean::API::DirectedAcyclicGraph> role which provide the following methods:
23  
24 =over 4
25  
26 =item C<< is_leaf >>
27  
28 =item C<< walk( prefix => \&pre_cb, postfix => \&pre_cb ) >>
29  
30 =item C<< cover( prefix => \&pre_cb, postfix => \&pre_cb ) >>
31  
32 =back
33  
34 and the following attributes:
35  
36 =over 4
37  
38 =item C<< children >>
39  
40 =back
41  
42 =head1 ATTRIBUTES
43  
44 The following attributes exist:
45  
46 =over 4
47  
48 =item C<< operator >>
49  
50 A string indicating the expression operator (e.g. C<'+'> or C<'||'>).
51  
52 =back
53  
54 =head1 REQUIRED METHODS
55  
56 The following methods are required by the L<Attean::API::Expression> role:
57  
58 =over 4
59  
60 =item C<< as_string >>
61  
62 Returns a string serialization of the expression object.
63  
64 =back
65  
66 =cut
67  
68 50 package Attean::API::Expression 0.040 {
69 50 ▶ use Types::Standard qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 50 with 'Attean::API::DirectedAcyclicGraph', 'Attean::API::UnionScopeVariables';
74
75 50 has 'operator' => (is => 'ro', isa => Str, required => 1);
76 50 requires 'is_stable'; # is stable for sorting (won't change across evaluations)
77 50 requires 'unaggregated_variables';
78 50 requires 'as_string';
79 50 requires 'as_sparql';
80
81 1440 ▶ sub BUILD {}
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
82 50 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 50 50
83 0 ▶ around 'BUILD' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
84 0 my $orig = shift;
85 0 my $self = shift;
86 0 $self->$orig(@_);
87 0 my $name = ref($self);
88 0 $name =~ s/^.*://;
89 0 ▶ if ($self->can('arity')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("arity")) 0 0 0
90 0 my $arity = $self->arity;
91 0 ▶ if (defined($arity)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arity) 0 0 0
92 0 my $children = $self->children;
93 0 my $size = scalar(@$children);
94 0 ▶ unless ($size == $arity) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($size == $arity) 0 0 0
95 0 die "${name} expression construction with bad number of children (expected $arity, but got $size)";
96 }
97 }
98 }
99 }
100 0 }
101 }
102  
103 50 package Attean::API::UnaryExpression 0.040 {
104 50 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 50 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
106  
107 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
108
109 50 with 'Attean::API::Expression', 'Attean::API::UnaryQueryTree';
110 50 with 'Attean::API::SPARQLSerializable';
111
112 2 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
113 2 my $self = shift;
114 2 my ($data) = @{ $self->children };
115 2 return sprintf("%s(%s)", $self->operator, $data->as_string);
116 }
117  
118 50 my %ops = (
119 '!' => AtteanX::SPARQL::Token->fast_constructor( BANG, -1, -1, -1, -1, ['!'] ),
120 '-' => AtteanX::SPARQL::Token->fast_constructor( MINUS, -1, -1, -1, -1, ['-'] ),
121 '+' => AtteanX::SPARQL::Token->fast_constructor( PLUS, -1, -1, -1, -1, ['+'] ),
122 );
123  
124 0 ▶ sub unaggregated_variables {
Subroutine unaggregated_variables: not called CC=1 SCAR=6.9
Pod undocumented
125 0 my $self = shift;
126 0 my ($child) = @{ $self->children };
127 0 return $child->unaggregated_variables;
128 }
129
130 0 ▶ sub sparql_tokens {
Subroutine sparql_tokens: not called CC=3 SCAR=24.8
Pod undocumented
131 0 my $self = shift;
132 0 ▶ my $op = $ops{$self->operator} // die "No operator found in Attean::API::UnaryExpression->sparql_tokens";
Condition0%0/2
$ops{$self->operator} // die("No operator found in Attean::API::UnaryExpression->sparql_tokens")
l!l
00
MC/DC0%0/1
$ops{$self->operator} // die("No operator found in Attean::API::UnaryExpression->sparql_tokens")
$ops{$self->operator}
Truth table0%0/2
A
A= $ops{$self->operator}
Aresult
11
00
133  
134 0 my @tokens;
135 0 push(@tokens, $op);
136 0 foreach my $t (@{ $self->children }) {
137 0 push(@tokens, $t->sparql_tokens->elements);
138 }
139 0 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
140 }
141 }
142  
143 50 package Attean::API::BinaryExpression 0.040 {
144 50 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
145 50 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
146  
147 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
148
149 50 with 'Attean::API::Expression', 'Attean::API::BinaryQueryTree';
150 50 with 'Attean::API::SPARQLSerializable';
151  
152 4 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
153 4 my $self = shift;
154 4 my ($lhs, $rhs) = @{ $self->children };
155 4 return sprintf("(%s %s %s)", $lhs->as_string, $self->operator, $rhs->as_string);
156 }
157  
158 0 ▶ sub unaggregated_variables {
Subroutine unaggregated_variables: not called CC=1 SCAR=6.9
Pod undocumented
159 0 my $self = shift;
160 0 return map { $_->unaggregated_variables } @{ $self->children };
161 }
162
163 50 my %ops = (
164 '-' => AtteanX::SPARQL::Token->fast_constructor( MINUS, -1, -1, -1, -1, ['-'] ),
165 '+' => AtteanX::SPARQL::Token->fast_constructor( PLUS, -1, -1, -1, -1, ['+'] ),
166 '*' => AtteanX::SPARQL::Token->fast_constructor( STAR, -1, -1, -1, -1, ['*'] ),
167 '/' => AtteanX::SPARQL::Token->fast_constructor( SLASH, -1, -1, -1, -1, ['/'] ),
168 '<' => AtteanX::SPARQL::Token->fast_constructor( LT, -1, -1, -1, -1, ['<'] ),
169 '>' => AtteanX::SPARQL::Token->fast_constructor( GT, -1, -1, -1, -1, ['>'] ),
170 '<=' => AtteanX::SPARQL::Token->fast_constructor( LE, -1, -1, -1, -1, ['<='] ),
171 '>=' => AtteanX::SPARQL::Token->fast_constructor( GE, -1, -1, -1, -1, ['>='] ),
172 '!=' => AtteanX::SPARQL::Token->fast_constructor( NOTEQUALS, -1, -1, -1, -1, ['!='] ),
173 '=' => AtteanX::SPARQL::Token->fast_constructor( EQUALS, -1, -1, -1, -1, ['='] ),
174 '&&' => AtteanX::SPARQL::Token->fast_constructor( ANDAND, -1, -1, -1, -1, ['&&'] ),
175 '||' => AtteanX::SPARQL::Token->fast_constructor( OROR, -1, -1, -1, -1, ['||'] ),
176 );
177
178 7 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=3 SCAR=11.0
Pod undocumented
179 7 my $self = shift;
180 7 ▶ my $op = $ops{$self->operator} // die "No operator found in Attean::API::BinaryExpression->sparql_tokens";
Condition50%1/2
$ops{$self->operator} // die("No operator found in Attean::API::BinaryExpression->sparql_tokens")
l!l
70
MC/DC0%0/1
$ops{$self->operator} // die("No operator found in Attean::API::BinaryExpression->sparql_tokens")
$ops{$self->operator}
Truth table50%1/2
A
A= $ops{$self->operator}
Aresult
11
00
181  
182 7 my @tokens;
183 7 foreach my $t (@{ $self->children }) {
184 14 push(@tokens, $t->sparql_tokens->elements);
185 14 push(@tokens, $op);
186 }
187 7 pop(@tokens);
188 7 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
189 }
190 }
191  
192 50 package Attean::API::NaryExpression 0.040 {
193 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 50 with 'Attean::API::Expression', 'Attean::API::QueryTree';
195 1 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod undocumented
196 1 my $self = shift;
197 1 my @children = map { $_->as_string } @{ $self->children };
198 1 return sprintf("%s(%s)", $self->operator, join(', ', @children));
199 }
200  
201 0 ▶ sub as_sparql {
Subroutine as_sparql: not called CC=1 SCAR=6.9
Pod undocumented
202 0 my $self = shift;
203 0 return $self->as_string;
204 }
205  
206 0 ▶ sub unaggregated_variables {
Subroutine unaggregated_variables: not called CC=1 SCAR=6.9
Pod undocumented
207 0 my $self = shift;
208 0 return map { $_->unaggregated_variables } @{ $self->children };
209 }
210 }
211  
212 50 package Attean::API::AggregateExpression 0.040 {
213 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
214 50 requires 'operator';
215 50 requires 'scalar_vars';
216 50 with 'Attean::API::Expression', 'Attean::API::DirectedAcyclicGraph';
217  
218 0 ▶ sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
219 0 my $self = shift;
220 0 my @children = map { $_->as_string } @{ $self->children };
221 0 return sprintf("%s(%s)", $self->operator, join(', ', @children));
222 }
223  
224 0 ▶ sub as_sparql {
Subroutine as_sparql: not called CC=1 SCAR=6.9
Pod undocumented
225 0 my $self = shift;
226 0 return $self->as_string;
227 }
228  
229 0 ▶ sub unaggregated_variables {
Subroutine unaggregated_variables: not called CC=1 SCAR=6.9
Pod undocumented
230 0 return;
231 }
232 }
233  
234 50 1;
235  
236 __END__
« AtteanX/API/JoinRotatingPlanner.pm ↑ Summary Attean/TripleModel.pm »