Query/Algebra/Construct.pm

filter: Statementstmt 85.3% 70 / 82 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.9% 17 / 21 Podpod 100% 11 / 11 totaltotal 80.0% 104 / 130 CC 7 SCAR 5.7
CC
7
Cov
81%
sse
3.0
as_sparql
3.0
pattern
2.1
CRAP 1.8
« Query/Algebra/Create.pm ↑ Summary Query/Parser/RDQL.pm »
1 # RDF::Query::Algebra::Construct
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Construct - Algebra class for construct query results
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Construct version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Construct;
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 Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 36 ▶use RDF::Trine::Iterator qw(sgrep);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 ######################################################################
28  
29 36 our ($VERSION);
30 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 36 $VERSION = '2.919';
32 }
33  
34 ######################################################################
35  
36 =head1 METHODS
37  
38 Beyond the methods documented below, this class inherits methods from the
39 L<RDF::Query::Algebra> class.
40  
41 =over 4
42  
43 =cut
44  
45 =item C<< new ( $query_pattern, \@construct_triples ) >>
46  
47 Returns a new Sort structure.
48  
49 =cut
50  
51 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
52 6 my $class = shift;
53 6 my $pattern = shift;
54 6 my $triples = shift;
55 6 return bless( [ $pattern, $triples ], $class );
56 }
57  
58 =item C<< construct_args >>
59  
60 Returns a list of arguments that, passed to this class' constructor,
61 will produce a clone of this algebra pattern.
62  
63 =cut
64  
65 4 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
66 4 my $self = shift;
67 4 my $pattern = $self->pattern;
68 4 my $triples = $self->triples;
69 4 return ($pattern, $triples);
70 }
71  
72 =item C<< pattern >>
73  
74 Returns the pattern used to produce the variable bindings used in graph construction.
75  
76 =cut
77  
78 16 ▶sub pattern {
Subroutine pattern: called CC=2 SCAR=7.6
Pod documented
79 16 my $self = shift;
80 16 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 16 16
81 0 $self->[0] = shift;
82 }
83 16 return $self->[0];
84 }
85  
86 =item C<< triples >>
87  
88 Returns an ARRAY ref of triples to be used in graph construction.
89  
90 =cut
91  
92 14 ▶sub triples {
Subroutine triples: called CC=2 SCAR=7.6
Pod documented
93 14 my $self = shift;
94 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 14 14
95 0 $self->[1] = shift;
96 }
97 14 return $self->[1];
98 }
99  
100 =item C<< sse >>
101  
102 Returns the SSE string for this algebra expression.
103  
104 =cut
105  
106 4 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.1
Pod documented
107 4 my $self = shift;
108 4 my $context = shift;
109 4 ▶ my $prefix = shift || '';
Condition50%1/2
shift() || ''
l!l
04
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
110 4 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
40
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
111 4 my $triples = join("\n${prefix}${indent}${indent}", map { $_->sse( $context, "${prefix}${indent}${indent}" ) } @{$self->triples});
112
113 4 return sprintf(
114 "(construct\n${prefix}${indent}(\n${prefix}${indent}${indent}%s\n${prefix}${indent})\n${prefix}${indent}%s)",
115 $triples,
116 $self->pattern->sse( $context, "${prefix}${indent}" ),
117 );
118 }
119  
120 =item C<< as_sparql >>
121  
122 Returns the SPARQL string for this algebra expression.
123  
124 =cut
125  
126 2 ▶sub as_sparql {
Subroutine as_sparql: called CC=3 SCAR=11.0
Pod documented
127 2 my $self = shift;
128 2 ▶ my $context = shift || {};
Condition50%1/2
shift() || {}
l!l
20
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
129 2 my $indent = shift;
130 2 my $triples = $self->triples;
131 2 my $bgp = RDF::Query::Algebra::BasicGraphPattern->new( @$triples );
132 2 my $ggp = RDF::Query::Algebra::GroupGraphPattern->new( $bgp );
133 2 ▶ my $force = $context->{ force_ggp_braces } || 0;
Condition50%1/2
$context->{'force_ggp_braces'} || 0
l!l
02
MC/DC0%0/1
$context->{'force_ggp_braces'} || 0
$context->{'force_ggp_braces'}
Truth table50%1/2
A
A= $context->{'force_ggp_braces'}
Aresult
11
00
134
135 2 my ($template, $pattern);
136 {
137 2 $context->{ force_ggp_braces } = $force + 1;
138 2 $template = $ggp->as_sparql( $context, $indent );
139 }
140 {
141 2 $context->{ force_ggp_braces } = $force + 1;
142 2 $pattern = $self->pattern->as_sparql( $context, $indent );
143 }
144
145 2 my $string = sprintf(
146 "CONSTRUCT %s\n${indent}WHERE %s",
147 $template,
148 $pattern,
149 );
150 2 return $string;
151 }
152  
153 =item C<< as_hash >>
154  
155 Returns the query as a nested set of plain data structures (no objects).
156  
157 =cut
158  
159 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
160 0 my $self = shift;
161 0 my $context = shift;
162 0 my $bgp = RDF::Query::Algebra::BasicGraphPattern->new( @{ $self->triples } );
163 return {
164 0 type => lc($self->type),
165 pattern => $self->pattern->as_hash,
166 construct => $bgp->as_hash,
167 };
168 }
169  
170 =item C<< type >>
171  
172 Returns the type of this algebra expression.
173  
174 =cut
175  
176 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
177 0 return 'CONSTRUCT';
178 }
179  
180 =item C<< referenced_variables >>
181  
182 Returns a list of the variable names used in this algebra expression.
183  
184 =cut
185  
186 2 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=1 SCAR=0.0
Pod documented
187 2 my $self = shift;
188 2 return RDF::Query::_uniq($self->pattern->referenced_variables);
189 }
190  
191 =item C<< potentially_bound >>
192  
193 Returns a list of the variable names used in this algebra expression that will
194 bind values during execution.
195  
196 =cut
197  
198 0 ▶sub potentially_bound {
Subroutine potentially_bound: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200 0 return $self->pattern->potentially_bound;
201 }
202  
203 =item C<< definite_variables >>
204  
205 Returns a list of the variable names that will be bound after evaluating this algebra expression.
206  
207 =cut
208  
209 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
210 0 my $self = shift;
211 0 return $self->pattern->definite_variables;
212 }
213  
214 36 1;
215  
216 __END__
« Query/Algebra/Create.pm ↑ Summary Query/Parser/RDQL.pm »