our
(
$VERSION
);
BEGIN {
$VERSION
=
'2.919'
;
}
sub
new {
my
$class
=
shift
;
my
$graph
=
shift
;
my
$self
=
$class
->SUPER::new(
$graph
);
return
$self
;
}
sub
execute ($) {
my
$self
=
shift
;
my
$context
=
shift
;
$self
->[0]{delegate} =
$context
->delegate;
if
(
$self
->state ==
$self
->OPEN) {
throw RDF::Query::Error::ExecutionError
-text
=>
"CLEAR plan can't be executed while already open"
;
}
my
$l
= Log::Log4perl->get_logger(
"rdf.query.plan.clear"
);
$l
->trace(
"executing RDF::Query::Plan::Clear"
);
my
%args
= (
$self
->namedgraph) ? (
context
=>
$self
->namedgraph) : ();
my
$graph
=
$self
->namedgraph;
unless
(
$graph
) {
$graph
= RDF::Trine::Node::Nil->new;
}
my
$ok
= 0;
try
{
if
(
$graph
->is_nil) {
$context
->model->remove_statements(
undef
,
undef
,
undef
,
$graph
);
}
else
{
my
$uri
=
$graph
->uri_value;
if
(
$uri
eq
'tag:gwilliams@cpan.org,2010-01-01:RT:ALL'
) {
$context
->model->remove_statements(
undef
,
undef
,
undef
,
undef
);
}
elsif
(
$uri
eq
'tag:gwilliams@cpan.org,2010-01-01:RT:NAMED'
) {
my
$citer
=
$context
->model->get_graphs;
while
(
my
$graph
=
$citer
->
next
) {
$context
->model->remove_statements(
undef
,
undef
,
undef
,
$graph
);
}
}
else
{
$context
->model->remove_statements(
undef
,
undef
,
undef
,
$graph
);
}
}
$ok
= 1;
}
catch
RDF::Trine::Error
with
{};
$self
->[0]{ok} =
$ok
;
$self
->state(
$self
->OPEN );
$self
;
}
sub
next
{
my
$self
=
shift
;
unless
(
$self
->state ==
$self
->OPEN) {
throw RDF::Query::Error::ExecutionError
-text
=>
"next() cannot be called on an un-open CLEAR"
;
}
my
$l
= Log::Log4perl->get_logger(
"rdf.query.plan.clear"
);
$self
->
close
();
if
(
my
$d
=
$self
->delegate) {
$d
->log_result(
$self
,
$self
->[0]{ok} );
}
return
$self
->[0]{ok};
}
sub
close
{
my
$self
=
shift
;
unless
(
$self
->state ==
$self
->OPEN) {
throw RDF::Query::Error::ExecutionError
-text
=>
"close() cannot be called on an un-open CLEAR"
;
}
delete
$self
->[0]{ok};
$self
->SUPER::
close
();
}
sub
namedgraph {
my
$self
=
shift
;
return
$self
->[1];
}
sub
distinct {
return
1;
}
sub
ordered {
return
[];
}
sub
plan_node_name {
return
'clear'
;
}
sub
plan_prototype {
my
$self
=
shift
;
my
$g
=
$self
->namedgraph;
if
(
$g
->isa(
'RDF::Query::Node::Resource'
) and
$g
->uri_value =~ m
'^tag:gwilliams@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$'
) {
return
qw(w)
;
}
else
{
return
qw(N)
;
}
}
sub
plan_node_data {
my
$self
=
shift
;
my
$g
=
$self
->namedgraph;
if
(
$g
->isa(
'RDF::Query::Node::Resource'
) and
$g
->uri_value =~ m
'^tag:gwilliams@cpan[.]org,2010-01-01:RT:(NAMED|ALL)$'
) {
return
$1;
}
else
{
return
(
$self
->namedgraph);
}
}
sub
graph {
my
$self
=
shift
;
my
$g
=
shift
;
my
$label
=
$self
->graph_labels;
my
$url
=
$self
->namedgraph->uri_value;
$g
->add_node(
"$self"
,
label
=>
"Clear"
.
$self
->graph_labels );
$g
->add_node(
"${self}$url"
,
label
=>
$url
);
$g
->add_edge(
"$self"
=>
"${self}$url"
,
label
=>
'url'
);
return
"$self"
;
}
sub
is_update {
return
1;
}
1;