Query/Algebra/Distinct.pm

filter: Statementstmt 76.1% 51 / 67 Branchbran 50.0% 1 / 2 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 77.2% 17 / 22 Podpod 100% 12 / 12 totaltotal 77.9% 85 / 109 CC 4 SCAR 4.3
CC
4
Cov
75%
sse
3.0
pattern
2.1
as_hash
2.0
CRAP 1.5
« Query/Algebra/Limit.pm ↑ Summary Query/Parser.pm »
1 # RDF::Query::Algebra::Distinct
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Distinct - Algebra class for distinct query results
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Distinct version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Distinct;
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 ( $pattern ) >>
46  
47 Returns a new Sort structure.
48  
49 =cut
50  
51 12 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
52 12 my $class = shift;
53 12 my $pattern = shift;
54 12 return bless( [ $pattern ], $class );
55 }
56  
57 =item C<< construct_args >>
58  
59 Returns a list of arguments that, passed to this class' constructor,
60 will produce a clone of this algebra pattern.
61  
62 =cut
63  
64 12 ▶sub construct_args {
Subroutine construct_args: called CC=1 SCAR=0.0
Pod documented
65 12 my $self = shift;
66 12 my $pattern = $self->pattern;
67 12 return ($pattern);
68 }
69  
70 =item C<< pattern >>
71  
72 Returns the pattern to be sorted.
73  
74 =cut
75  
76 41 ▶sub pattern {
Subroutine pattern: called CC=2 SCAR=7.6
Pod documented
77 41 my $self = shift;
78 41 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 41 41
79 0 $self->[0] = shift;
80 }
81 41 return $self->[0];
82 }
83  
84 =item C<< sse >>
85  
86 Returns the SSE string for this algebra expression.
87  
88 =cut
89  
90 15 ▶sub sse {
Subroutine sse: called CC=3 SCAR=11.0
Pod documented
91 15 my $self = shift;
92 15 my $context = shift;
93 15 ▶ my $prefix = shift || '';
Condition100%2/2
shift() || ''
l!l
510
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
94 15 ▶ my $indent = $context->{indent} || ' ';
Condition50%1/2
$context->{'indent'} || ' '
l!l
150
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table50%1/2
A
A= $context->{'indent'}
Aresult
11
00
95
96 15 return sprintf(
97 "(distinct\n${prefix}${indent}%s)",
98 $self->pattern->sse( $context, "${prefix}${indent}" ),
99 );
100 }
101  
102 =item C<< as_sparql >>
103  
104 Returns the SPARQL string for this algebra expression.
105  
106 =cut
107  
108 2 ▶sub as_sparql {
Subroutine as_sparql: called CC=1 SCAR=0.0
Pod documented
109 2 my $self = shift;
110 2 my $context = shift;
111 2 my $indent = shift;
112
113 2 return 'DISTINCT ' . $self->pattern->as_sparql( $context, $indent );
114 }
115  
116 =item C<< as_hash >>
117  
118 Returns the query as a nested set of plain data structures (no objects).
119  
120 =cut
121  
122 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
123 0 my $self = shift;
124 0 my $context = shift;
125 return {
126 0 type => lc($self->type),
127 pattern => $self->pattern->as_hash,
128 };
129 }
130  
131 =item C<< as_spin ( $model ) >>
132  
133 Adds statements to the given model to represent this algebra object in the
134 SPARQL Inferencing Notation (L<http://www.spinrdf.org/>).
135  
136 =cut
137  
138 0 ▶sub as_spin {
Subroutine as_spin: not called CC=1 SCAR=6.9
Pod documented
139 0 my $self = shift;
140 0 my $model = shift;
141 0 my $spin = RDF::Trine::Namespace->new('http://spinrdf.org/spin#');
142 0 my $xsd = RDF::Trine::Namespace->new('http://www.w3.org/2001/XMLSchema#');
143 0 my $q = $self->pattern->as_spin( $model );
144
145 0 $model->add_statement( RDF::Trine::Statement->new($q, $spin->distinct, RDF::Query::Node::Literal->new('true', undef, $xsd->boolean)) );
146
147 0 return $q;
148 }
149  
150 =item C<< type >>
151  
152 Returns the type of this algebra expression.
153  
154 =cut
155  
156 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
157 0 return 'DISTINCT';
158 }
159  
160 =item C<< referenced_variables >>
161  
162 Returns a list of the variable names used in this algebra expression.
163  
164 =cut
165  
166 2 ▶sub referenced_variables {
Subroutine referenced_variables: called CC=1 SCAR=0.0
Pod documented
167 2 my $self = shift;
168 2 return RDF::Query::_uniq($self->pattern->referenced_variables);
169 }
170  
171 =item C<< potentially_bound >>
172  
173 Returns a list of the variable names used in this algebra expression that will
174 bind values during execution.
175  
176 =cut
177  
178 0 ▶sub potentially_bound {
Subroutine potentially_bound: not called CC=1 SCAR=6.9
Pod documented
179 0 my $self = shift;
180 0 return $self->pattern->potentially_bound;
181 }
182  
183 =item C<< definite_variables >>
184  
185 Returns a list of the variable names that will be bound after evaluating this algebra expression.
186  
187 =cut
188  
189 0 ▶sub definite_variables {
Subroutine definite_variables: not called CC=1 SCAR=6.9
Pod documented
190 0 my $self = shift;
191 0 return $self->pattern->definite_variables;
192 }
193  
194 =item C<< is_solution_modifier >>
195  
196 Returns true if this node is a solution modifier.
197  
198 =cut
199  
200 10 ▶sub is_solution_modifier {
Subroutine is_solution_modifier: called CC=1 SCAR=0.0
Pod documented
201 10 return 1;
202 }
203  
204  
205 36 1;
206  
207 __END__
« Query/Algebra/Limit.pm ↑ Summary Query/Parser.pm »