Query/Algebra/Table.pm

filter: Statementstmt 35.7% 34 / 95 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 11 / 22 Podpod 100% 10 / 10 totaltotal 38.7% 55 / 142 CC 13 SCAR 24.5
CC
13
Cov
32%
as_sparql
42.0
new
12.0
sse
12.0
CRAP 11.6
« Query/Algebra/Extend.pm ↑ Summary Query/Plan/ComputedStatement.pm »
1 # RDF::Query::Algebra::Table
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Algebra::Table - Algebra class for constant table data
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Algebra::Table version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Algebra::Table;
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 Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(blessed refaddr reftype);
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 Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use RDF::Trine::Iterator qw(smap swatch);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ######################################################################
29  
30 36 our ($VERSION);
31 36 my %AS_SPARQL;
32 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
33 36 $VERSION = '2.919';
34 }
35  
36 ######################################################################
37  
38 =head1 METHODS
39  
40 Beyond the methods documented below, this class inherits methods from the
41 L<RDF::Query::Algebra> class.
42  
43 =over 4
44  
45 =cut
46  
47 =item C<< new ( \@variables, $row1, $row2, ... ) >>
48  
49 Returns a new Table structure.
50  
51 =cut
52  
53 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
54 0 my $class = shift;
55 0 my $vars = shift;
56 0 my @rows = @_;
57 0 foreach my $t (@rows) {
58 0 ▶ unless ($t->isa('RDF::Trine::VariableBindings')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t->isa("RDF::Trine::VariableBindings")) 0 0 0
59 0 throw RDF::Query::Error::QueryPatternError -text => "Rows belonging to a table must be variable bindings";
60 }
61 }
62 0 return bless( [ $vars, \@rows ], $class );
63 }
64  
65 =item C<< construct_args >>
66  
67 Returns a list of arguments that, passed to this class' constructor,
68 will produce a clone of this algebra pattern.
69  
70 =cut
71  
72 0 ▶sub construct_args {
Subroutine construct_args: not called CC=1 SCAR=6.9
Pod documented
73 0 my $self = shift;
74 0 return ([$self->variables], $self->rows);
75 }
76  
77 =item C<< variables >>
78  
79 Returns a list of variable names used in this data table.
80  
81 =cut
82  
83 0 ▶sub variables {
Subroutine variables: not called CC=1 SCAR=6.9
Pod documented
84 0 my $self = shift;
85 0 return @{ $self->[0] };
86 }
87  
88 =item C<< rows >>
89  
90 Returns a list of variable bindings belonging to this data table.
91  
92 =cut
93  
94 0 ▶sub rows {
Subroutine rows: not called CC=1 SCAR=6.9
Pod documented
95 0 my $self = shift;
96 0 return @{ $self->[1] };
97 }
98  
99 =item C<< sse >>
100  
101 Returns the SSE string for this algebra expression.
102  
103 =cut
104  
105 0 ▶sub sse {
Subroutine sse: not called CC=3 SCAR=24.8
Pod documented
106 0 my $self = shift;
107 0 my $context = shift;
108 0 ▶ my $prefix = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
109 0 ▶ my $indent = $context->{indent} || ' ';
Condition0%0/2
$context->{'indent'} || ' '
l!l
00
MC/DC0%0/1
$context->{'indent'} || ' '
$context->{'indent'}
Truth table0%0/2
A
A= $context->{'indent'}
Aresult
11
00
110 0 my @rows = sort map { $_->sse( $context ) } $self->rows;
111 0 return sprintf(
112 "(table\n${prefix}${indent}%s\n${prefix})",
113 join("\n${prefix}${indent}", @rows)
114 );
115 }
116  
117 =item C<< explain >>
118  
119 Returns a string serialization of the algebra appropriate for display on the
120 command line.
121  
122 =cut
123  
124 0 ▶sub explain {
Subroutine explain: not called CC=2 SCAR=17.9
Pod documented
125 0 my $self = shift;
126 0 my $s = shift;
127 0 my $count = shift;
128 0 my $indent = $s x $count;
129 0 my $string = "${indent}table\n";
130
131 0 foreach my $t ($self->rows) {
132 0 $string .= $t->explain($s, $indent+1);
133 }
134 0 return $string;
135 }
136  
137  
138 =item C<< as_sparql >>
139  
140 Returns the SPARQL string for this algebra expression.
141  
142 =cut
143  
144 0 ▶sub as_sparql {
Subroutine as_sparql: not called CC=6 SCAR=37.4
Pod documented
145 0 my $self = shift;
146 0 ▶ if (exists $AS_SPARQL{ refaddr( $self ) }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $AS_SPARQL{builtin::refaddr($self)}) { } 0 0 0
147 0 return $AS_SPARQL{ refaddr( $self ) };
148 } else {
149 0 my $context = shift;
150 # if (ref($context)) {
151 # $context = { %$context };
152 # }
153 0 ▶ my $indent = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
154 0 my @values;
155 0 my @vars = $self->variables;
156 0 foreach my $row ($self->rows) {
157 0 my @row_values;
158 0 foreach my $var (@vars) {
159 0 my $node = $row->{$var};
160 0 ▶ my $value = ($node) ? $node->as_sparql($context, $indent) : 'UNDEF';
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 0 0 0
161 0 push(@row_values, $value);
162 }
163 0 push(@values, '(' . join(' ', @row_values) . ')');
164 }
165 0 my $vars = join(' ', map { "?$_" } @vars);
166 0 my $string = "VALUES ($vars) {\n${indent}" . join("\n${indent}", @values) . "\n}\n";
167 0 $AS_SPARQL{ refaddr( $self ) } = $string;
168 0 return $string;
169 }
170 }
171  
172 =item C<< as_hash >>
173  
174 Returns the query as a nested set of plain data structures (no objects).
175  
176 =cut
177  
178 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
179 0 my $self = shift;
180 0 my $context = shift;
181 return {
182 type => lc($self->type),
183 0 patterns => [ map { $_->as_hash } $self->rows ],
184 };
185 }
186  
187 =item C<< type >>
188  
189 Returns the type of this algebra expression.
190  
191 =cut
192  
193 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
194 0 return 'TABLE';
195 }
196  
197 =item C<< referenced_variables >>
198  
199 Returns a list of the variable names used in this algebra expression.
200  
201 =cut
202  
203 0 ▶sub referenced_variables {
Subroutine referenced_variables: not called CC=3 SCAR=24.8
Pod documented
204 0 my $self = shift;
205 0 my %vars;
206 0 foreach my $r ($self->rows) {
207 0 $vars{ $_ }++ foreach (keys %$r);
208 }
209 0 return keys %vars;
210 }
211  
212 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
213 0 my $self = shift;
214 0 delete $AS_SPARQL{ refaddr( $self ) };
215 }
216  
217 36 1;
218  
219 __END__
« Query/Algebra/Extend.pm ↑ Summary Query/Plan/ComputedStatement.pm »