NAME

RDF::KV::Patch - Representation of RDF statements to be added or removed

VERSION

Version 0.13

SYNOPSIS

my $patch = RDF::KV::Patch->new;

$patch->add_this($s, $p, $o, $g);
$patch->remove_this($s, $p, undef, $g); # a wildcard

$patch->apply($model); # an RDF::Trine::Model instance

DESCRIPTION

This module is designed to represent a diff for RDF graphs. You add statements to its add or remove sides, then you "apply" them to a RDF::Trine::Model object. This should probably be part of RDF::Trine if there isn't something like this in there already.

METHODS

new

Stub constructor, nothing of interest.

add_this { $S, $P, $O | $statement } [, $graph ]

Add a statement, or set of terms, to the add side of the patch.

This method and its siblings are fairly robust, and can take a wide variety of inputs, from triple and quad statements, to individual subject/predicate/object/graph objects, to string literals, to variable nodes, to undef. They are processed by the following scheme:

dont_add_this { $S, $P, $O | $statement } [, $graph ]

Remove a statement, or set of terms, from the add side of the patch.

remove_this { $S, $P, $O | $statement } [, $graph ]

Add a statement, or set of terms, to the remove side of the patch.

dont_remove_this { $S, $P, $O | $statement } [, $graph ]

Remove a statement, or set of terms, from the remove side of the patch.

affected_graphs

Return the set of graph identifiers affected by the patch, including undef for the null graph.

subjects_affected [$use_graphs]

Return the set of subjects that are affected by the patch, irrespective of graph.

to_add

In list context, returns an array of statements to add to the graph. In scalar context, returns an RDF::Trine::Iterator.

to_remove

In list context, returns an array of statements to remove from the graph. In scalar context, returns an RDF::Trine::Iterator.

apply { $model | $remove, $add }

Apply the patch to an RDF::Trine::Model object. Statements are removed first, then added. Transactions (i.e. "begin_bulk_ops" in RDF::Trine::Model) are your responsibility.

Alternatively, supply the remove and add functions directly:

sub _remove_or_add {
  my ($subject, $predicate, $object, $graph) = @_;

  # do stuff ...

  # return value is ignored
}

Inputs will be either RDF::Trine::Node objects, or undef, in the case of remove.

SEE ALSO

RDF::KV
RDF::Trine::Model
RDF::Trine::Statement
RDF::Trine::Node

LICENSE AND COPYRIGHT

Copyright 2013 Dorian Taylor.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.