Query/Algebra/Optional.pm

filter: Statementstmt 76.9% 50 / 65 Branchbran n/a Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 85.0% 17 / 20 Podpod 100% 12 / 12 totaltotal 80.5% 83 / 103 CC 3 SCAR 3.4
CC
3
Cov
77%
sse
3.0
as_spin
2.0
as_hash
2.0
CRAP 1.4
« Query/Parser.pm ↑ Summary Query/Algebra/Offset.pm »
1 # RDF::Query::Algebra::Optional
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Optional - Algebra class for Optional patterns
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Optional version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Optional;
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 Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use RDF::Trine::Iterator qw(smap sgrep swatch);
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 Beyond the methods documented below, this class inherits methods from the
37 L<RDF::Query::Algebra> class.
38  
39 =over 4
40  
41 =cut
42  
43 =item C<new ( $pattern, $opt_pattern )>
44  
45 Returns a new Optional structure.
46  
47 =cut
48  
49 14 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
50 14 my $class = shift;
51 14 my $pattern = shift;
52 14 my $opt = shift;
53 14 return bless( [ 'OPTIONAL', $pattern, $opt ], $class );
54 }
55  
56 =item C<< construct_args >>
57  
58 Returns a list of arguments that, passed to this class' constructor,
59 will produce a clone of this algebra pattern.
60  
61 =cut
62  
63 52 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
64 52 my $self = shift;
65 52 return ($self->pattern, $self->optional);
66 }
67  
68 =item C<< pattern >>
69  
70 Returns the base pattern (LHS) onto which the optional pattern joins.
71  
72 =cut
73  
74 109 ▶sub pattern {
Subroutine pattern: called CC=1 SCAR=0.0
Pod documented
75 109 my $self = shift;
76 109 return $self->[1];
77 }
78  
79 =item C<< optional >>
80  
81 Returns the optional pattern (RHS).
82  
83 =cut
84  
85 107 ▶sub optional {
Subroutine optional: called CC=1 SCAR=0.0
Pod documented
86 107 my $self = shift;
87 107 return $self->[2];
88 }
89  
90 =item C<< sse >>
91  
92 Returns the SSE string for this algebra expression.
93  
94 =cut
95  
96 38 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.0
Pod documented
97 38 my $self = shift;
98 38 my $context = shift;
99 38 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
1721
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
100 38 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
380
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
101
102 38 return sprintf(
103 "(leftjoin\n${prefix}${indent}%s\n${prefix}${indent}%s)",
104 $self->pattern->sse( $context, "${prefix}${indent}" ),
105 $self->optional->sse( $context, "${prefix}${indent}" )
106 );
107 }
108  
109 =item C<< as_sparql >>
110  
111 Returns the SPARQL string for this algebra expression.
112  
113 =cut
114  
115 2 ▶sub as_sparql {
Subroutine as_sparql: called CC=1 SCAR=0.0
Pod documented
116 2 my $self = shift;
117 2 my $context = shift;
118 2 my $indent = shift;
119 2 my $string = sprintf(
120 "%s\n${indent}OPTIONAL %s",
121 $self->pattern->as_sparql( $context, $indent ),
122 $self->optional->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ),
123 );
124 2 return $string;
125 }
126  
127 =item C<< as_spin ( $model ) >>
128  
129 Adds statements to the given model to represent this algebra object in the
130 SPARQL Inferencing Notation (L<http://www.spinrdf.org/>).
131  
132 =cut
133  
134 0 ▶sub as_spin {
Subroutine as_spin: not called CC=1 SCAR=6.9
Pod documented
135 0 my $self = shift;
136 0 my $model = shift;
137 0 my $spin = RDF::Trine::Namespace->new('http://spinrdf.org/spin#');
138 0 my $rdf = RDF::Trine::Namespace->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
139 0 my @lhs = $self->pattern->as_spin($model);
140 0 my @rhs = $self->optional->as_spin($model);
141 0 my $opt = RDF::Query::Node::Blank->new();
142 0 my $list = $model->add_list( @rhs );
143 0 $model->add_statement( RDF::Trine::Statement->new($opt, $rdf->type, $spin->Optional) );
144 0 $model->add_statement( RDF::Trine::Statement->new($opt, $spin->elements, $list) );
145 0 return (@lhs, $opt);
146 }
147  
148 =item C<< as_hash >>
149  
150 Returns the query as a nested set of plain data structures (no objects).
151  
152 =cut
153  
154 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
155 0 my $self = shift;
156 0 my $context = shift;
157 return {
158 0 type => lc($self->type),
159 pattern => $self->pattern->as_hash,
160 optional => $self->optional->as_hash,
161 };
162 }
163  
164 =item C<< type >>
165  
166 Returns the type of this algebra expression.
167  
168 =cut
169  
170 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
171 0 return 'OPTIONAL';
172 }
173  
174 =item C<< referenced_variables >>
175  
176 Returns a list of the variable names used in this algebra expression.
177  
178 =cut
179  
180 2 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=1 SCAR=0.0
Pod documented
181 2 my $self = shift;
182 2 return RDF::Query::_uniq($self->pattern->referenced_variables, $self->optional->referenced_variables);
183 }
184  
185 =item C<< potentially_bound >>
186  
187 Returns a list of the variable names used in this algebra expression that will
188 bind values during execution.
189  
190 =cut
191  
192 2 ▶sub potentially_bound {
Subroutine potentially_bound: called CC=1 SCAR=0.0
Pod documented
193 2 my $self = shift;
194 2 return RDF::Query::_uniq($self->pattern->potentially_bound, $self->optional->potentially_bound);
195 }
196  
197 =item C<< definite_variables >>
198  
199 Returns a list of the variable names that will be bound after evaluating this algebra expression.
200  
201 =cut
202  
203 2 ▶sub definite_variables {
Subroutine definite_variables: called CC=1 SCAR=0.0
Pod documented
204 2 my $self = shift;
205 2 return $self->pattern->definite_variables;
206 }
207  
208 36 1;
209  
210 __END__
« Query/Parser.pm ↑ Summary Query/Algebra/Offset.pm »