Query/Plan/Clear.pm

filter: Statementstmt 30.9% 30 / 97 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 41.6% 10 / 24 Podpod 100% 12 / 12 totaltotal 31.1% 52 / 167 CC 15 SCAR 22.9
CC
15
Cov
24%
__ANON__
30.0
execute
20.0
next
12.0
CRAP 9.9
« Query/Algebra/BasicGraphPattern.pm ↑ Summary Query/Plan/Sequence.pm »
1 # RDF::Query::Plan::Clear
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Plan::Clear - Executable query plan for CLEAR operations.
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Plan::Clear version 2.919.
11  
12 =head1 METHODS
13  
14 Beyond the methods documented below, this class inherits methods from the
15 L<RDF::Query::Plan> class.
16  
17 =over 4
18  
19 =cut
20  
21 package RDF::Query::Plan::Clear;
22  
23 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 35 ▶use base qw(RDF::Query::Plan);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 35 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 35 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 35 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 35 ▶use RDF::Query::Error qw(:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 35 ▶use RDF::Query::ExecutionContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 35 ▶use RDF::Query::VariableBindings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 ######################################################################
36  
37 35 our ($VERSION);
38 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
39 35 $VERSION = '2.919';
40 }
41  
42 ######################################################################
43  
44 =item C<< new ( $graph ) >>
45  
46 =cut
47  
48 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
49 0 my $class = shift;
50 0 my $graph = shift;
51 0 my $self = $class->SUPER::new( $graph );
52 0 return $self;
53 }
54  
55 =item C<< execute ( $execution_context ) >>
56  
57 =cut
58  
59 0 ▶sub execute ($) {
Subroutine execute: not called CC=4 SCAR=30.0
Pod documented
60 0 my $self = shift;
61 0 my $context = shift;
62 0 $self->[0]{delegate} = $context->delegate;
63 0 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 0 0
64 0 throw RDF::Query::Error::ExecutionError -text => "CLEAR plan can't be executed while already open";
65 }
66
67 0 my $l = Log::Log4perl->get_logger("rdf.query.plan.clear");
68 0 $l->trace( "executing RDF::Query::Plan::Clear" );
69
70 0 ▶ my %args = ($self->namedgraph) ? (context => $self->namedgraph) : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->namedgraph ? : 0 0 0
71 0 my $graph = $self->namedgraph;
72 0 ▶ unless ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($graph) 0 0 0
73 0 $graph = RDF::Trine::Node::Nil->new;
74 }
75 # warn "clearing graph " . $graph->as_string;
76 0 my $ok = 0;
77 0 ▶ try {
Subroutine __ANON__: not called CC=5 SCAR=34.0
78 0 ▶ if ($graph->is_nil) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->is_nil) { } 0 0 0
79 0 $context->model->remove_statements( undef, undef, undef, $graph );
80 } else {
81 0 my $uri = $graph->uri_value;
82 0 ▶ if ($uri eq 'tag:gwilliams@cpan.org,2010-01-01:RT:ALL') {
Branch: 2 branches
BranchTrueFalseTotal
if ($uri eq 'tag:gwilliams@cpan.org,2010-01-01:RT:ALL') { } 0 0 0
elsif ($uri eq 'tag:gwilliams@cpan.org,2010-01-01:RT:NAMED') { } 0 0 0
83 0 $context->model->remove_statements( undef, undef, undef, undef );
84 } elsif ($uri eq 'tag:gwilliams@cpan.org,2010-01-01:RT:NAMED') {
85 0 my $citer = $context->model->get_graphs;
86 0 ▶ while (my $graph = $citer->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $graph = $citer->next) 0 0 0
87 0 $context->model->remove_statements( undef, undef, undef, $graph );
88 }
89 } else {
90 0 $context->model->remove_statements( undef, undef, undef, $graph );
91 }
92 }
93 0 $ok = 1;
94 0 ▶ } catch RDF::Trine::Error with {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 $self->[0]{ok} = $ok;
96 0 $self->state( $self->OPEN );
97 0 $self;
98 }
99  
100 =item C<< next >>
101  
102 =cut
103  
104 0 ▶sub next {
Subroutine next: not called CC=3 SCAR=24.8
Pod documented
105 0 my $self = shift;
106 0 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 0 0
107 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open CLEAR";
108 }
109
110 0 my $l = Log::Log4perl->get_logger("rdf.query.plan.clear");
111 0 $self->close();
112 0 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 0 0
113 0 $d->log_result( $self, $self->[0]{ok} );
114 }
115 0 return $self->[0]{ok};
116 }
117  
118 =item C<< close >>
119  
120 =cut
121  
122 0 ▶sub close {
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
123 0 my $self = shift;
124 0 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 0 0
125 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open CLEAR";
126 }
127
128 0 delete $self->[0]{ok};
129 0 $self->SUPER::close();
130 }
131  
132 =item C<< namedgraph >>
133  
134 Returns the graph node which is to be cleared.
135  
136 =cut
137  
138 0 ▶sub namedgraph {
Subroutine namedgraph: not called CC=1 SCAR=6.9
Pod documented
139 0 my $self = shift;
140 0 return $self->[1];
141 }
142  
143 =item C<< distinct >>
144  
145 Returns true if the pattern is guaranteed to return distinct results.
146  
147 =cut
148  
149 0 ▶sub distinct {
Subroutine distinct: not called CC=1 SCAR=6.9
Pod documented
150 0 return 1;
151 }
152  
153 =item C<< ordered >>
154  
155 Returns true if the pattern is guaranteed to return ordered results.
156  
157 =cut
158  
159 0 ▶sub ordered {
Subroutine ordered: not called CC=1 SCAR=6.9
Pod documented
160 0 return [];
161 }
162  
163 =item C<< plan_node_name >>
164  
165 Returns the string name of this plan node, suitable for use in serialization.
166  
167 =cut
168  
169 0 ▶sub plan_node_name {
Subroutine plan_node_name: not called CC=1 SCAR=6.9
Pod documented
170 0 return 'clear';
171 }
172  
173 =item C<< plan_prototype >>
174  
175 Returns a list of scalar identifiers for the type of the content (children)
176 nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
177 identifiers.
178  
179 =cut
180  
181 0 ▶sub plan_prototype {
Subroutine plan_prototype: not called CC=3 SCAR=24.8
Pod documented
182 0 my $self = shift;
183 0 my $g = $self->namedgraph;
184 0 ▶ if ($g->isa('RDF::Query::Node::Resource') and $g->uri_value =~ m'^tag:gwilliams@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($g->isa('RDF::Query::Node::Resource') and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/) { } 0 0 0
Condition0%0/3
$g->isa("RDF::Query::Node::Resource") and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$g->isa("RDF::Query::Node::Resource") and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
$g->isa("RDF::Query::Node::Resource") $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
Truth table0%0/3
A and B
A= $g->isa("RDF::Query::Node::Resource")B= $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
ABresult
0X0
100
111
185 0 return qw(w);
186 } else {
187 0 return qw(N);
188 }
189 }
190  
191 =item C<< plan_node_data >>
192  
193 Returns the data for this plan node that corresponds to the values described by
194 the signature returned by C<< plan_prototype >>.
195  
196 =cut
197  
198 0 ▶sub plan_node_data {
Subroutine plan_node_data: not called CC=3 SCAR=24.8
Pod documented
199 0 my $self = shift;
200 0 my $g = $self->namedgraph;
201 0 ▶ if ($g->isa('RDF::Query::Node::Resource') and $g->uri_value =~ m'^tag:gwilliams@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($g->isa('RDF::Query::Node::Resource') and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/) { } 0 0 0
Condition0%0/3
$g->isa("RDF::Query::Node::Resource") and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$g->isa("RDF::Query::Node::Resource") and $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
$g->isa("RDF::Query::Node::Resource") $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
Truth table0%0/3
A and B
A= $g->isa("RDF::Query::Node::Resource")B= $g->uri_value =~ /^tag:gwilliams\@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$/
ABresult
0X0
100
111
202 0 return $1;
203 } else {
204 0 return ($self->namedgraph);
205 }
206 }
207  
208 =item C<< graph ( $g ) >>
209  
210 =cut
211  
212 0 ▶sub graph {
Subroutine graph: not called CC=1 SCAR=6.9
Pod documented
213 0 my $self = shift;
214 0 my $g = shift;
215 0 my $label = $self->graph_labels;
216 0 my $url = $self->namedgraph->uri_value;
217 0 $g->add_node( "$self", label => "Clear" . $self->graph_labels );
218 0 $g->add_node( "${self}$url", label => $url );
219 0 $g->add_edge( "$self" => "${self}$url", label => 'url' );
220 0 return "$self";
221 }
222  
223 =item C<< is_update >>
224  
225 Returns true if the plan represents an update operation.
226  
227 =cut
228  
229 0 ▶sub is_update {
Subroutine is_update: not called CC=1 SCAR=6.9
Pod documented
230 0 return 1;
231 }
232  
233 35 1;
234  
235 __END__
« Query/Algebra/BasicGraphPattern.pm ↑ Summary Query/Plan/Sequence.pm »