RDF::KV::Patch - Representation of RDF statements to be added or removed
Version 0.05
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
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.
Stub constructor, nothing of interest.
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:
If passed a RDF::Trine::Statement, it will be unwound into its respective components. The graph attribute of a quad statement supersedes any given graph parameter.
graph
The empty string, undef, and RDF::Trine::Node::Variable objects are considered to be wildcards, which are only legal in the negative side of the patch, since they don't make sense on the positive side. Placing wildcards in all three of the subject, predicate and object positions will raise an exception, because if carried out it would completely empty the graph. If you're sure you want to do that, you should use another mechanism.
undef
Subjects are coerced from string literals to URI and URI::BNode instances and from there to RDF::Trine::Node::Resource and RDF::Trine::Node::Blank instances, respectively.
Predicates are always coerced from string literals or URI objects into RDF::Trine::Node::Resource objects.
Objects are coerced from either string literals or ARRAY references into RDF::Trine::Node::Literal instances, the latter case mimicking that class's constructor. URIs or blank nodes must already be at least instances of URI or URI::BNode, if not RDF::Trine::Node::Resource or RDF::Trine::Node::Blank. Note: the empty string is considered a wildcard, so if you want an actual empty string, you will need to pass in an RDF::Trine::Node::Literal with that value.
ARRAY
Remove a statement, or set of terms, from the add side of the patch.
Add a statement, or set of terms, to the remove side of the patch.
Remove a statement, or set of terms, from the remove side of the patch.
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:
remove
add
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.
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.
To install RDF::KV, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RDF::KV
CPAN shell
perl -MCPAN -e shell install RDF::KV
For more information on module installation, please visit the detailed CPAN module installation guide.