Query/Plan/Copy.pm

filter: Statementstmt 30.9% 30 / 97 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 38.4% 10 / 26 Podpod 100% 14 / 14 totaltotal 36.2% 54 / 149 CC 7 SCAR 14.0
CC
7
Cov
28%
__ANON__
12.0
next
12.0
execute
6.0
CRAP 4.1
« Query/Plan/Move.pm ↑ Summary Query/Plan/Load.pm »
1 # RDF::Query::Plan::Copy
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Plan::Copy - Executable query plan for COPY operations.
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Plan::Copy 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::Copy;
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 ( $from, $to, $silent ) >>
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 $from = shift;
51 0 my $to = shift;
52 0 my $silent = shift;
53 0 my $self = $class->SUPER::new( $from, $to, $silent );
54 0 return $self;
55 }
56  
57 =item C<< execute ( $execution_context ) >>
58  
59 =cut
60  
61 0 ▶sub execute ($) {
Subroutine execute: not called CC=2 SCAR=17.9
Pod documented
62 0 my $self = shift;
63 0 my $context = shift;
64 0 $self->[0]{delegate} = $context->delegate;
65 0 ▶ if ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->state == $self->OPEN) 0 0 0
66 0 throw RDF::Query::Error::ExecutionError -text => "COPY plan can't be executed while already open";
67 }
68
69 0 my $l = Log::Log4perl->get_logger("rdf.query.plan.copy");
70 0 $l->trace( "executing RDF::Query::Plan::Copy" );
71
72 0 my $from = $self->from;
73 0 my $to = $self->to;
74 # warn "Copying graph " . $from->as_string;
75 0 my $ok = 0;
76 0 ▶ try {
Subroutine __ANON__: not called CC=3 SCAR=24.8
77 0 ▶ if ($from->equal( $to )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from->equal($to)) { } 0 0 0
78 # no-op
79 } else {
80 0 my $model = $context->model;
81 0 $model->begin_bulk_ops();
82 0 $model->remove_statements( undef, undef, undef, $to );
83 0 my $iter = $model->get_statements( undef, undef, undef, $from );
84 0 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
85 0 $model->add_statement( $st, $to );
86 }
87 0 $model->end_bulk_ops();
88 }
89 0 $ok = 1;
90 0 ▶ } catch RDF::Trine::Error with {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 $self->[0]{ok} = $ok;
92 0 $self->state( $self->OPEN );
93 0 $self;
94 }
95  
96 =item C<< next >>
97  
98 =cut
99  
100 0 ▶sub next {
Subroutine next: not called CC=3 SCAR=24.8
Pod documented
101 0 my $self = shift;
102 0 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 0 0
103 0 throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open COPY";
104 }
105
106 0 my $l = Log::Log4perl->get_logger("rdf.query.plan.copy");
107 0 $self->close();
108 0 ▶ if (my $d = $self->delegate) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->delegate) 0 0 0
109 0 $d->log_result( $self, $self->[0]{ok} );
110 }
111 0 return $self->[0]{ok};
112 }
113  
114 =item C<< close >>
115  
116 =cut
117  
118 0 ▶sub close {
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
119 0 my $self = shift;
120 0 ▶ unless ($self->state == $self->OPEN) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->state == $self->OPEN) 0 0 0
121 0 throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open COPY";
122 }
123
124 0 delete $self->[0]{ok};
125 0 $self->SUPER::close();
126 }
127  
128 =item C<< from >>
129  
130 Returns the graph node which is to be copied.
131  
132 =cut
133  
134 0 ▶sub from {
Subroutine from: not called CC=1 SCAR=6.9
Pod documented
135 0 my $self = shift;
136 0 return $self->[1];
137 }
138  
139 =item C<< to >>
140  
141 Returns the graph node to which data is copied.
142  
143 =cut
144  
145 0 ▶sub to {
Subroutine to: not called CC=1 SCAR=6.9
Pod documented
146 0 my $self = shift;
147 0 return $self->[2];
148 }
149  
150 =item C<< silent >>
151  
152 Returns the silent flag.
153  
154 =cut
155  
156 0 ▶sub silent {
Subroutine silent: not called CC=1 SCAR=6.9
Pod documented
157 0 my $self = shift;
158 0 return $self->[3];
159 }
160  
161 =item C<< distinct >>
162  
163 Returns true if the pattern is guaranteed to return distinct results.
164  
165 =cut
166  
167 0 ▶sub distinct {
Subroutine distinct: not called CC=1 SCAR=6.9
Pod documented
168 0 return 1;
169 }
170  
171 =item C<< ordered >>
172  
173 Returns true if the pattern is guaranteed to return ordered results.
174  
175 =cut
176  
177 0 ▶sub ordered {
Subroutine ordered: not called CC=1 SCAR=6.9
Pod documented
178 0 return [];
179 }
180  
181 =item C<< plan_node_name >>
182  
183 Returns the string name of this plan node, suitable for use in serialization.
184  
185 =cut
186  
187 0 ▶sub plan_node_name {
Subroutine plan_node_name: not called CC=1 SCAR=6.9
Pod documented
188 0 return 'copy';
189 }
190  
191 =item C<< plan_prototype >>
192  
193 Returns a list of scalar identifiers for the type of the content (children)
194 nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
195 identifiers.
196  
197 =cut
198  
199 0 ▶sub plan_prototype {
Subroutine plan_prototype: not called CC=1 SCAR=6.9
Pod documented
200 0 my $self = shift;
201 0 return qw(N N);
202 }
203  
204 =item C<< plan_node_data >>
205  
206 Returns the data for this plan node that corresponds to the values described by
207 the signature returned by C<< plan_prototype >>.
208  
209 =cut
210  
211 0 ▶sub plan_node_data {
Subroutine plan_node_data: not called CC=1 SCAR=6.9
Pod documented
212 0 my $self = shift;
213 0 return ($self->from, $self->to);
214 }
215  
216 =item C<< graph ( $g ) >>
217  
218 =cut
219  
220 0 ▶sub graph {
Subroutine graph: not called CC=1 SCAR=6.9
Pod documented
221 0 my $self = shift;
222 0 my $g = shift;
223 0 my $label = $self->graph_labels;
224 0 my $furl = $self->from->uri_value;
225 0 my $turl = $self->to->uri_value;
226 0 $g->add_node( "$self", label => "Copy" . $self->graph_labels );
227 0 $g->add_node( "${self}$furl", label => $furl );
228 0 $g->add_node( "${self}$turl", label => $turl );
229 0 $g->add_edge( "$self" => "${self}$furl", label => 'from' );
230 0 $g->add_edge( "$self" => "${self}$turl", label => 'to' );
231 0 return "$self";
232 }
233  
234 =item C<< is_update >>
235  
236 Returns true if the plan represents an update operation.
237  
238 =cut
239  
240 0 ▶sub is_update {
Subroutine is_update: not called CC=1 SCAR=6.9
Pod documented
241 0 return 1;
242 }
243  
244 35 1;
245  
246 __END__
« Query/Plan/Move.pm ↑ Summary Query/Plan/Load.pm »