KV.pm

filter: Statementstmt 22.5% 68 / 301 Branchbran 0.0% 0 / 148 Conditioncond 0.0% 0 / 91 MC/DCmcdc 0.0% 0 / 53 Subroutinesub 47.0% 16 / 34 Podpod 100% 1 / 1 totaltotal 13.5% 85 / 628 CC 130 SCAR 84.6
CC
130
Cov
13%
process
8372.0
_massage_macros
342.0
_deref_content
272.0
CRAP 4739.3
↑ Summary KV/Patch.pm »
1 package RDF::KV;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # might as well use full-blown moose if URI::NamespaceMap uses it
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use XML::RegExp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Data::GUID::Any ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Data::UUID::NCName ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use URI::BNode;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use URI::NamespaceMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 # XXX remind me to rewrite this using Moo.
23  
24 2 ▶use RDF::KV::Patch;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 =head1 NAME
27  
28 RDF::KV - Embed RDF linked data in plain old HTML forms
29  
30 =head1 VERSION
31  
32 Version 0.14
33  
34 =cut
35  
36 2 our $VERSION = '0.14';
37  
38 2 class_type 'URI';
39  
40 # here's ye olde grammar:
41  
42 # XXX I know I said in the spec that the protocol should be parseable
43 # by a single regex, but regexes make for lame, all-or-nothing
44 # parsers. As such, this should really be rewritten when there's time
45 # to create a more helpful (in the error message sense) parser.
46  
47 # ok you know what? no. This is waaaaaaay simpler.
48 2 my $MODIFIER = qr/(?:[!=+-]|[+-]!|![+-])/o;
49 2 my $PREFIX = qr/(?:$XML::RegExp::NCName|[A-Za-z][0-9A-Za-z.+-]*)/o;
50 2 my $TERM = qr/(?:$PREFIX:\S*)/o;
51 2 my $RFC5646 = qr/(?:[A-Za-z]+(?:-[0-9A-Za-z]+)*)/o;
52 2 my $DESIGNATOR = qr/(?:[:_']|\@$RFC5646|\^$TERM)/o;
53 2 my $DECLARATION = qr/^\s*\$\s+($XML::RegExp::NCName)(?:\s+(\$))?\s*$/mo;
54 2 my $MACRO = qr/(?:\$\{($XML::RegExp::NCName)\}|
55 \$($XML::RegExp::NCName))/xo;
56 2 my $NOT_MACRO = qr/(?:(?!\$$XML::RegExp::NCName|
57 \$\{$XML::RegExp::NCName\}).)*/xso;
58 2 my $MACROS = qr/($NOT_MACRO)(?:$MACRO)?($NOT_MACRO)/smo;
59 2 my $PARTIAL_STMT = qr/^\s*(?:($MODIFIER)\s+)?
60 (?:($TERM)(?:\s+($TERM))?(?:\s+($DESIGNATOR))?|
61 ($TERM)\s+($DESIGNATOR)\s+($TERM)|
62 ($TERM)\s+($TERM)(?:\s+($DESIGNATOR))?\s+($TERM))
63 (?:\s+(\$))?\s*$/xsmo;
64  
65 2 my @MAP = qw(modifier term1 term2 designator term1 designator graph
66 term1 term2 designator graph deref);
67  
68 =head1 SYNOPSIS
69  
70 my $kv = RDF::KV->new(
71 subject => $uri, # ordinarily the Request-URI
72 graph => $graphuri, # URI for the default graph
73 namespaces => $ns, # default namespace prefix map
74 callback => \&rewrite, # form-results-rewriting callback
75 );
76  
77 # Processes a hashref-of-parameters, like found in Catalyst or
78 # Plack::Request. This call will ignore obviously non-matching
79 # keys, but will croak on botched attempts to use the protocol.
80  
81 my $patch = eval { $kv->process($params) };
82 if ($@) {
83 # return 409 Conflict ...
84 }
85  
86 # add/remove statements from the graph
87 $patch->apply($model);
88  
89 =head1 DESCRIPTION
90  
91 This module provides a reference implementation for the L<RDF-KV
92 protocol|http://doriantaylor.com/rdf-kv>. The objective of this
93 protocol is to convey RDF linked data from a web browser to a web
94 server using no mechanism beyond conventional
95 C<application/x-www-form-urlencoded> HTML forms. The overarching
96 purpose is to facilitate the development of linked data applications
97 by making the apparatus of JavaScript an I<optional>, rather than a
98 I<mandatory>, consideration.
99  
100 This protocol implementation works by culling key-value pairs denoted
101 in a prescribed syntax from POSTed form input (parsed by something
102 like L<CGI>, L<Plack::Request> or L<Catalyst>), and then stitching
103 them together to create a L<patch object|RDF::KV::Patch> which is then
104 applied to an L<RDF::Trine::Model> graph.
105  
106 =head1 METHODS
107  
108 =head2 new
109  
110 Instantiate the object. The following parameters are also (read-only)
111 accessors.
112  
113 =over 4
114  
115 =item subject
116  
117 This is the default subject URI (or blank node).
118  
119 =cut
120  
121 2 has subject => (
122 is => 'rw',
123 isa => 'Str|URI',
124 required => 1,
125 );
126  
127 =item graph
128  
129 This is the default graph URI.
130  
131 =cut
132  
133 2 has graph => (
134 is => 'rw',
135 isa => 'Str|URI',
136 default => '',
137 );
138  
139 =item namespaces
140  
141 This L<URI::NamespaceMap> object will enable URI abbreviation through
142 the use of CURIEs in form input.
143  
144 =cut
145  
146 has namespaces => (
147 is => 'ro',
148 isa => 'URI::NamespaceMap',
149 0 ▶ default => sub { URI::NamespaceMap->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 2 );
151  
152 =item callback
153  
154 Supply a callback function that will be applied to subject and object
155 values, for instance to rewrite a URI. The return value of this
156 function must be understood by L<RDF::KV::Patch/add_this>.
157  
158 =cut
159  
160 has callback => (
161 is => 'ro',
162 isa => 'CodeRef',
163 0 ▶ default => sub { sub { shift } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
164 2 );
165  
166 =back
167  
168 =head2 process \%CONTENT
169  
170 Process form content and return an L<RDF::KV::Patch> object. This is
171 the only significant method.
172  
173 =cut
174  
175 # variants of parameter getters
176  
177 0 ▶sub _1 {
Subroutine _1: not called CC=1 SCAR=6.9
178 0 my ($params, $k) = @_;
179 0 $params->get_all($k);
180 }
181  
182 0 ▶sub _2 {
Subroutine _2: not called CC=2 SCAR=17.9
183 0 my ($params, $k) = @_;
184 0 my $val = $params->{$k};
185 0 ▶ ref $val ? @$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 0 0 0
186 }
187  
188 0 ▶sub _uuid4 () {
Subroutine _uuid4: not called CC=1 SCAR=6.9
189 0 lc Data::GUID::Any::v4_guid_as_string();
190 }
191  
192 0 ▶sub _uuid4urn () {
Subroutine _uuid4urn: not called CC=1 SCAR=6.9
193 0 'urn:uuid:' . _uuid4;
194 }
195  
196 0 ▶sub _uuid4bn () {
Subroutine _uuid4bn: not called CC=1 SCAR=6.9
197 0 URI::BNode->new;
198 }
199  
200 # XXX these should all get syntax checks/CURIE expansion/etc
201 my %SPECIALS = (
202 0 ▶ SUBJECT => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
203 0 my ($self, $val) = @_;
204 0 ▶ $self->subject($val->[-1]) if @$val;
Branch: 1 branch
BranchTrueFalseTotal
if @$val 0 0 0
205 },
206 0 ▶ GRAPH => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
207 0 my ($self, $val) = @_;
208 0 ▶ $self->graph($val->[-1]) if @$val;
Branch: 1 branch
BranchTrueFalseTotal
if @$val 0 0 0
209 },
210 0 ▶ PREFIX => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
211 0 my ($self, $val) = @_;
212 # XXX CHECK THIS MUTHA
213 0 for my $v (@$val) {
214 #warn $v;
215 0 ▶ my ($prefix, $uri) = ($v =~ /^\s*(\S+):\s+(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
() = $v =~ /^\s*(\S+):\s+(.*)$/ or Carp::croak("Invalid prefix mapping $val") 0 0 0
216 or Carp::croak("Invalid prefix mapping $val");
217 #warn $uri;
218 0 $self->namespaces->add_mapping($prefix, $uri);
219 }
220 },
221 2 );
222  
223 2 my %GENERATED = (
224 NEW_UUID => [[\&_uuid4, 0]],
225 NEW_UUID_URN => [[\&_uuid4urn, 0]],
226 NEW_BNODE => [[\&_uuid4bn, 0]],
227 );
228  
229 0 ▶sub _deref_content {
Subroutine _deref_content: not called CC=16 SCAR=56.1
230 0 my ($val, $macros) = @_;
231 0 my @out;
232  
233 # if $val is scalar, this loop will run just once.
234 0 ▶ for my $v (ref $val ? @$val : ($val)) {
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 0 0 0
235 # make this versatile
236 0 ▶ $v = $v->[0] if ref $v;
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 0 0
237  
238 0 my @chunks;
239 0 ▶ while ($v =~ /\G$MACROS/gco) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\G$MACROS/cog) 0 0 0
240 #warn "seen me";
241 0 my $pre = $1;
242 0 ▶ my $macro = $2 || $3;
Condition0%0/3
$2 || $3
l!l&&r!l&&!r
000
MC/DC0%0/2
$2 || $3
$2 $3
Truth table0%0/3
A || B
A= $2B= $3
ABresult
1X1
011
000
243 0 my $post = $4;
244  
245 0 ▶ unless (defined $macro) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $macro) 0 0 0
246 0 ▶ if (@chunks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chunks) { } 0 0 0
247 0 @chunks = map { "$_$pre$post" } @chunks;
248 }
249 else {
250 0 @chunks = ($pre . $post);
251 }
252 0 next;
253 }
254  
255 # do the actual macro dereferencing or noop in
256 # lieu of a bound macro
257 0 my @x = (defined $macros->{$macro} && @{$macros->{$macro}} ?
258 0 ▶ (map { sprintf('%s%s%s',
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
259 $pre, ref $_ ? &$_ : $_, $post)
260 0 ▶ } @{$macros->{$macro}}) : ("$pre\$$macro$post"));
Branch: 1 branch
BranchTrueFalseTotal
defined $macros->{$macro} && @{$macros->{$macro};} ? : 0 0 0
Condition0%0/3
defined $macros->{$macro} and @{$macros->{$macro};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $macros->{$macro} and @{$macros->{$macro};}
defined $macros->{$macro} @{$macros->{$macro};}
Truth table0%0/3
A and B
A= defined $macros->{$macro}B= @{$macros->{$macro};}
ABresult
0X0
100
111
261 # XXX LOLOLOL THIS IS THE MOST ILLEGIBLE PILE OF NONSENSE
262  
263 # it says: if a macro value is present, sub it or no-op,
264 # but if the macro is a code ref, run it.
265  
266 #warn 'wat: ' . Data::Dumper::Dumper(\@x);
267  
268 # initialize chunks
269 0 ▶ unless (@chunks) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@chunks) 0 0 0
270 #warn 'correct!';
271 0 @chunks = @x;
272 0 next;
273 }
274  
275 # replace chunks with product of itself and x
276 0 ▶ if (@x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@x) 0 0 0
277 0 my @y;
278 0 for my $c (@chunks) {
279 0 for my $d (@x) {
280 #warn 'halp wtf';
281 0 push @y, "$c$d";
282 }
283 }
284 0 @chunks = @y;
285 }
286 }
287  
288 0 push @out, @chunks;
289 }
290 #warn 'hurr: ' . Data::Dumper::Dumper(\@out);
291  
292  
293 0 ▶ wantarray ? @out : \@out;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
294 }
295  
296 0 ▶sub _massage_macros {
Subroutine _massage_macros: not called CC=18 SCAR=58.3
297 0 my $macros = shift;
298 # XXX this currently makes destructive changes to $macros insofar
299 # as it rewrites the 'deref' flag with the actual variables to
300 # dereference, or to 0 if there aren't any. If this becomes a
301 # problem, just use Clone.
302  
303 # cycle detect, finished product
304 0 my (%seen, %done);
305  
306 # shallow-copy the hash
307 0 my %pending = %$macros;
308  
309 # get rid of generated
310 0 map { delete $pending{$_} } keys %GENERATED;
311  
312 # Start a queue with a (quasi) random macro.
313 0 my @queue = (keys %pending)[0];
314  
315 # If none of them contain a (bound) macro references, that macro
316 # is 'done'.
317  
318 # If the values *do* contain bound macro references, check to see
319 # if those are 'done'. If they aren't, *prepend* the keys to the
320 # queue, before the current macro.
321  
322 0 ▶ while (@queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 0 0 0
323 #warn 'Initial ' . join(';', @queue);
324 0 my $k = shift @queue;
325 #warn "beginning \$$k";
326  
327 0 $seen{$k}++;
328  
329 0 my @vals = @{$macros->{$k}};
330  
331 # 'done' and 'pending' macros
332 0 my (%dm, %pm);
333  
334 # Examine each of its values.
335  
336 # Note: this test is equivalent to concatenating the values
337 # together with spaces and performing the regex on that. But
338 # we can't do that because we're storing the macro-matching
339 # state of individual values.
340 0 for my $pair (@vals) {
341 0 my ($val, $deref) = @$pair;
342  
343 # no expando
344 0 ▶ next unless $deref;
Branch: 1 branch
BranchTrueFalseTotal
unless $deref 0 0 0
345  
346 0 ▶ if (ref $deref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $deref) { } 0 0 0
347 # already been scanned
348 0 for my $m (@$deref) {
349 0 ▶ defined $done{$m} ? $dm{$m}++ : $pm{$m}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $done{$m} ? : 0 0 0
350 }
351 }
352 else {
353 0 my %m;
354 0 for my $m (grep { defined $_ } ($val =~ /$MACRO/og)) {
355  
356 # check first to see if it's bound
357 0 ▶ next unless $macros->{$m};
Branch: 1 branch
BranchTrueFalseTotal
unless $macros->{$m} 0 0 0
358 #warn $m;
359  
360 # if it's yourself, explode
361 0 ▶ Carp::croak("Self reference found!") if $m eq $k;
Branch: 1 branch
BranchTrueFalseTotal
if $m eq $k 0 0 0
362  
363 # get this to replace deref
364 0 $m{$m}++;
365  
366 # and get this to figure out if we can deref
367 0 ▶ defined $done{$m} ? $dm{$m}++ : $pm{$m}++;
Branch: 1 branch
BranchTrueFalseTotal
defined $done{$m} ? : 0 0 0
368 }
369  
370 # now replace deref
371 0 ▶ $pair->[1] = keys %m ? [sort keys %m] : 0;
Branch: 1 branch
BranchTrueFalseTotal
keys %m ? : 0 0 0
372 }
373 }
374  
375 # macro values have pending matches
376 0 ▶ if (keys %pm) {
Branch: 2 branches
BranchTrueFalseTotal
if (keys %pm) { } 0 0 0
elsif (keys %dm) { } 0 0 0
377 # this is where we would detect a cycle
378  
379 # right HERE
380  
381 0 my @q;
382 0 for my $m (keys %pm) {
383 0 ▶ Carp::croak("Cycle detected between $k and $m") if $seen{$m};
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$m} 0 0 0
384 0 push @q, $m;
385 }
386 #warn join '/', @q;
387  
388 # do it again
389 0 unshift @queue, @q, $k;
390 #warn join ',', @queue;
391  
392 0 next;
393 }
394 elsif (keys %dm) {
395 # macro values have actionable matches
396  
397 #warn "replacing values for \$$k";
398  
399 # replace contents and mark done
400 0 $done{$k} = _deref_content(\@vals, \%done);
401 }
402 else {
403 #warn Data::Dumper::Dumper(\@vals);
404 # nothing to do, mark done
405 0 $done{$k} = [map { $_->[0] } @vals];
406 }
407  
408 # remember to remove this guy or we'll loop forever
409 0 delete $pending{$k};
410  
411 # replenish the queue with another pending object
412 0 ▶ push @queue, (keys %pending)[0] if !@queue and keys %pending;
Branch: 1 branch
BranchTrueFalseTotal
if not @queue and keys %pending 0 0 0
Condition0%0/3
not @queue and keys %pending
!ll&&!rl&&r
000
MC/DC0%0/2
not @queue and keys %pending
not @queue keys %pending
Truth table0%0/3
not(A) and B
A= not @queueB= keys %pending
ABresult
0X0
100
111
413 }
414  
415 0 \%done;
416 }
417  
418  
419 0 ▶sub process {
Subroutine process: not called CC=91 SCAR=90.3
Pod documented
420 0 my ($self, $params) = @_;
421  
422 # assume this can also be a Hash::MultiValue
423 0 ▶ my $sub = Scalar::Util::blessed($params)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($params) && $params->can('get_all') ? : 0 0 0
Condition0%0/3
builtin::blessed($params) and $params->can("get_all")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($params) and $params->can("get_all")
builtin::blessed($params) $params->can("get_all")
Truth table0%0/3
A and B
A= builtin::blessed($params)B= $params->can("get_all")
ABresult
0X0
100
111
424 && $params->can('get_all') ? \&_1 : \&_2;
425 # XXX do we want to do ->isa instead?
426  
427 # begin by seeding macros with generators
428 0 my %macros = %GENERATED;
429  
430 0 my (%maybe, %neither);
431  
432 0 for my $k (keys %$params) {
433 # Step 0: get the values into a homogeneous list
434 0 my @v = $sub->($params, $k);
435  
436 # Step 1: pull out all the macro declarations
437 0 ▶ if (my ($name, $sigil) = ($k =~ $DECLARATION)) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = $k =~ /$DECLARATION/) { } 0 0 0
elsif ($k =~ /^\s*\S+\s+\S+.*?/ or $k =~ /[:\$]/) { } 0 0 0
438 # Step 1.0.1: create [content, deref flag] pairs
439  
440 # skip over generated macros
441 0 ▶ next if $GENERATED{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $GENERATED{$name} 0 0 0
442  
443 # OOH VERY CLEVER
444 0 ▶ push @{$macros{$name} ||= []}, (map { [$_, int(!!$sigil)] } @v);
Condition0%0/2
$macros{$name} ||= []
l!l
00
MC/DC0%0/1
$macros{$name} ||= []
$macros{$name}
Truth table0%0/2
A
A= $macros{$name}
Aresult
11
00
445 }
446 # Step 1.1: set aside candidate statements
447 ▶ elsif ($k =~ /^\s*\S+\s+\S+.*?/ or $k =~ /[:\$]/) {
Condition0%0/3
$k =~ /^\s*\S+\s+\S+.*?/ or $k =~ /[:\$]/
l!l&&r!l&&!r
000
MC/DC0%0/2
$k =~ /^\s*\S+\s+\S+.*?/ or $k =~ /[:\$]/
$k =~ /^\s*\S+\s+\S+.*?/ $k =~ /[:\$]/
Truth table0%0/3
A or B
A= $k =~ /^\s*\S+\s+\S+.*?/B= $k =~ /[:\$]/
ABresult
1X1
011
000
448 # valid partial statements will contain space or : or $
449 0 ▶ push @{$maybe{$k} ||= []}, @v;
Condition0%0/2
$maybe{$k} ||= []
l!l
00
MC/DC0%0/1
$maybe{$k} ||= []
$maybe{$k}
Truth table0%0/2
A
A= $maybe{$k}
Aresult
11
00
450 }
451 # Step 1.2: put the rest in a discard pile
452 else {
453 0 ▶ push @{$neither{$k} ||= []}, @v;
Condition0%0/2
$neither{$k} ||= []
l!l
00
MC/DC0%0/1
$neither{$k} ||= []
$neither{$k}
Truth table0%0/2
A
A= $neither{$k}
Aresult
11
00
454 }
455 }
456  
457 # cycles should cause a 409 Conflict error, but that isn't our job
458 # here.
459  
460 # XXX although it may be useful to return an object in $@ that was
461 # more informative.
462  
463 # Step 2: dereference all the macros (that asked to be)
464 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
465 0 my $x = _massage_macros(\%macros);
466 0 %macros = %$x;
467 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
468 # move this error up in the stack
469 0 Carp::croak($@);
470 0 };
471  
472 # Step 2.1: overwrite any reserved/magic macros
473 #$macros{NEW_UUID} = [[\&_uuid4, 1]];
474 #$macros{NEW_UUID_URN} = [[\&_uuid4urn, 1]];
475 #$macros{NEW_BNODE} = [[\&_uuid4bn, 1]];
476 # XXX make this extensible?
477  
478 # Step 3: apply special control macros to $self
479 0 ▶ try {
Subroutine __ANON__: not called CC=3 SCAR=24.8
480 0 for my $k (keys %SPECIALS) {
481 0 ▶ next unless $macros{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $macros{$k} 0 0 0
482 0 $SPECIALS{$k}->($self, $macros{$k});
483 }
484 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
485 # cough any errors up the stack
486 0 Carp::croak($@);
487 0 };
488  
489 #require Data::Dumper;
490 #warn Data::Dumper::Dumper(\%macros);
491  
492  
493 # add/remove statements
494 0 my $patch = RDF::KV::Patch->new;
495 0 my (%pos, %neg);
496 0 for my $k (keys %maybe) {
497 # Step 4: dereference macros in statements
498  
499 # Step 4.1 dereference macros in statement *templates* first
500 # so we can figure out which values need to be dereferenced
501 # (since the terminating $ indicator can be substituted in via
502 # macro).
503 0 ▶ my @k = grep { defined $_ } ($k =~ /$MACRO/og) ?
Branch: 1 branch
BranchTrueFalseTotal
$k =~ /$MACRO/go ? : 0 0 0
504 _deref_content($k, \%macros) : ($k);
505  
506 # we want to check the values for empty strings *before* we
507 # dereference them so it's still possible to express the empty
508 # string through the use of a macro
509 0 my @v = grep { $_ ne '' } map { $_ =~ s/^\s*(.*?)\s*$/$1/sm; $_ }
510 0 ▶ grep { defined $_ } @{$maybe{$k} || []};
Condition0%0/2
$maybe{$k} || []
l!l
00
MC/DC0%0/1
$maybe{$k} || []
$maybe{$k}
Truth table0%0/2
A
A= $maybe{$k}
Aresult
11
00
511  
512 #require Data::Dumper;
513 #warn Data::Dumper::Dumper($maybe{$k});
514  
515 # very well could loop just once here
516 0 for my $template (@k) {
517 #warn "lol $template";
518  
519 # nope actually we're parsing the template now
520 0 my @tokens = ($template =~ $PARTIAL_STMT);
521  
522 #warn scalar @tokens;
523  
524 # ignore if there wasn't a match XXX WARN SOMEHOW?
525 0 ▶ next unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 0 0
526  
527 # do not ignore, however, if this screws up
528 0 ▶ die 'INTERNAL ERROR: regex does not match map'
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens == @MAP 0 0 0
529 unless @tokens == @MAP;
530  
531 # now make a nice hash of the contents
532 0 my %contents;
533 map {
534 0 ▶ $contents{$MAP[$_]} = $tokens[$_] if defined $tokens[$_]
Branch: 1 branch
BranchTrueFalseTotal
if defined $tokens[$_] 0 0 0
535 } (0..$#MAP);
536  
537 # just to recap, %contents can contain, at maximum:
538 # * modifier (reverse statement, negate, etc)
539 # * term1 (either subject or predicate)
540 # * term2 (either predicate or object)
541 # * designator (treat input values as URI/blank/literal[type?])
542 # * graph URI
543 # * macro-dereference instruction
544  
545 # pull out the statement modifier first
546 $contents{modifier} = {
547 0 ▶ map { $_ => 1 } (split //, $contents{modifier} || '') };
Condition0%0/2
$contents{'modifier'} || ''
l!l
00
MC/DC0%0/1
$contents{'modifier'} || ''
$contents{'modifier'}
Truth table0%0/2
A
A= $contents{'modifier'}
Aresult
11
00
548  
549 # now deal with designator
550 0 ▶ if ($contents{designator}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'designator'}) { } 0 0 0
551 0 my ($sigil, $symbol) = ($contents{designator} =~ /^(.)(.*)$/);
552  
553 Carp::croak("Reversed statement templates " .
554 "cannot specify literals ($template)")
555 0 ▶ if ($contents{modifier}{'!'} and $sigil =~ /['@^]/);
Branch: 1 branch
BranchTrueFalseTotal
if $contents{"modifier"}{"!"} and $sigil =~ /['\@^]/ 0 0 0
Condition0%0/3
$contents{"modifier"}{"!"} and $sigil =~ /['\@^]/
!ll&&!rl&&r
000
MC/DC0%0/2
$contents{"modifier"}{"!"} and $sigil =~ /['\@^]/
$contents{"modifier"}{"!"} $sigil =~ /['\@^]/
Truth table0%0/3
A and B
A= $contents{"modifier"}{"!"}B= $sigil =~ /['\@^]/
ABresult
0X0
100
111
556  
557 0 ▶ if ($sigil eq '^') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sigil eq "^") 0 0 0
558 # expand datatype URI
559 0 ▶ $symbol = $self->namespaces->uri($symbol) || $symbol;
Condition0%0/3
$self->namespaces->uri($symbol) || $symbol
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->namespaces->uri($symbol) || $symbol
$self->namespaces->uri($symbol) $symbol
Truth table0%0/3
A || B
A= $self->namespaces->uri($symbol)B= $symbol
ABresult
1X1
011
000
560 }
561  
562 $contents{designator} =
563 0 ▶ $symbol eq '' ? [$sigil] : [$sigil, $symbol];
Branch: 1 branch
BranchTrueFalseTotal
$symbol eq '' ? : 0 0 0
564 }
565 else {
566 # single-tick is the default designator for forward
567 # statements, : is for reverse.
568 $contents{designator} = [
569 0 ▶ $contents{modifier}{'!'} ? ':' : q/'/ ];
Branch: 1 branch
BranchTrueFalseTotal
$contents{'modifier'}{'!'} ? : 0 0 0
570 }
571  
572 # now we should expand the rest of the abbreviations
573 0 for my $which (qw(term1 term2 graph)) {
574 0 ▶ if (defined $contents{$which}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $contents{$which}) 0 0 0
575 my $uri = $self->namespaces->uri($contents{$which})
576 0 ▶ || $contents{$which};
Condition0%0/3
$self->namespaces->uri($contents{$which}) || $contents{$which}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->namespaces->uri($contents{$which}) || $contents{$which}
$self->namespaces->uri($contents{$which}) $contents{$which}
Truth table0%0/3
A || B
A= $self->namespaces->uri($contents{$which})B= $contents{$which}
ABresult
1X1
011
000
577 # XXX should we do some sort of relative uri
578 # resolution thing?
579 0 $contents{$which} = $uri;
580 }
581 }
582  
583 # I suppose we can do this now
584 0 ▶ if ($contents{deref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{"deref"}) 0 0 0
585 # XXX might want to trim bounding whitespace again
586 0 @v = map { _deref_content($_, \%macros) } @v;
587 }
588  
589 #require Data::Dumper;
590 #warn Data::Dumper::Dumper([\%contents, \@v]);
591  
592 # statement reversal behaviour is not entirely symmetric.
593  
594 # + is a noop of the default behaviour: assert S P O or O P S.
595 # = means remove S P * before asserting S P O. (no reversal)
596 # - means either remove S P *, S P O or O P S, but not O P *.
597  
598 # No, you know what? Restricting reverse wildcards is
599 # going to make it a hell of a problem to do things like
600 # completely disconnect one resource from another set of
601 # resources. This protocol has to assume the end user is
602 # allowed to make these kinds of changes. We'll mop up the
603 # permission stuff elsewhere.
604  
605 # thinking this oughta do it:
606 # { g => { s => { p => [{ o => 1 }, { langordt => { o => 1 }}]}}}
607  
608 0 ▶ my $g = $contents{graph} || $self->graph;
Condition0%0/3
$contents{'graph'} || $self->graph
l!l&&r!l&&!r
000
MC/DC0%0/2
$contents{'graph'} || $self->graph
$contents{'graph'} $self->graph
Truth table0%0/3
A || B
A= $contents{'graph'}B= $self->graph
ABresult
1X1
011
000
609  
610 0 ▶ if ($contents{modifier}{'!'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'modifier'}{'!'}) { } 0 0 0
611 # reverse statement (O P S)
612 0 my $p = $contents{term1};
613 0 ▶ my $o = URI::BNode->new($contents{term2} || $self->subject);
Condition0%0/3
$contents{'term2'} || $self->subject
l!l&&r!l&&!r
000
MC/DC0%0/2
$contents{'term2'} || $self->subject
$contents{'term2'} $self->subject
Truth table0%0/3
A || B
A= $contents{'term2'}B= $self->subject
ABresult
1X1
011
000
614  
615 # don't forget to do this
616 0 ▶ $o = $self->callback->($o) if $self->callback;
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
617  
618 # you know what, it makes no sense for a reverse
619 # statement to be anything but a URI or a blank node.
620  
621 0 ▶ next unless $contents{designator}[0] =~ /[_:]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $contents{"designator"}[0] =~ /[_:]/ 0 0 0
622  
623 0 ▶ if ($contents{modifier}{'-'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'modifier'}{'-'}) { } 0 0 0
624 # remove these triples
625 0 for my $s (@v) {
626 0 ▶ if ($contents{designator}[0] eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'designator'}[0] eq '_') { } 0 0 0
627 0 ▶ $s = '_:' . $s unless $s =~ /^_:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /^_:/ 0 0 0
628 }
629 else {
630 0 $s = URI->new_abs($s, $o);
631 0 ▶ $s = $self->callback->($s) if $self->callback;
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
632 }
633  
634 0 ▶ $neg{$g} ||= {};
Condition0%0/2
$neg{$g} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g} ||= {}
$neg{$g}
Truth table0%0/2
A
A= $neg{$g}
Aresult
11
00
635 0 ▶ $neg{$g}{$s} ||= {};
Condition0%0/2
$neg{$g}{$s} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g}{$s} ||= {}
$neg{$g}{$s}
Truth table0%0/2
A
A= $neg{$g}{$s}
Aresult
11
00
636 0 ▶ $neg{$g}{$s}{$p} ||= [{}, {}];
Condition0%0/2
$neg{$g}{$s}{$p} ||= [{}, {}]
l!l
00
MC/DC0%0/1
$neg{$g}{$s}{$p} ||= [{}, {}]
$neg{$g}{$s}{$p}
Truth table0%0/2
A
A= $neg{$g}{$s}{$p}
Aresult
11
00
637 0 ▶ $neg{$g}{$s}{$p}[0]{$o} = 1 if ref $neg{$g}{$s}{$p};
Branch: 1 branch
BranchTrueFalseTotal
if ref $neg{$g}{$s}{$p} 0 0 0
638  
639 0 $patch->remove_this($s, $p, $o, $g);
640 }
641 }
642 else {
643 # add these triples
644 0 for my $s (@v) {
645 0 ▶ next if $s eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 0 0 0
646 0 ▶ if ($contents{designator}[0] eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'designator'}[0] eq '_') { } 0 0 0
647 0 ▶ $s = '_:' . $s unless $s =~ /^_:/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /^_:/ 0 0 0
648 }
649 else {
650 0 $s = URI->new_abs($s, $o);
651 0 ▶ $s = $self->callback->($s) if $self->callback;
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
652 }
653  
654 0 ▶ $pos{$g} ||= {};
Condition0%0/2
$pos{$g} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g} ||= {}
$pos{$g}
Truth table0%0/2
A
A= $pos{$g}
Aresult
11
00
655 0 ▶ $pos{$g}{$s} ||= {};
Condition0%0/2
$pos{$g}{$s} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g}{$s} ||= {}
$pos{$g}{$s}
Truth table0%0/2
A
A= $pos{$g}{$s}
Aresult
11
00
656 0 ▶ $pos{$g}{$s}{$p} ||= [{}, {}];
Condition0%0/2
$pos{$g}{$s}{$p} ||= [{}, {}]
l!l
00
MC/DC0%0/1
$pos{$g}{$s}{$p} ||= [{}, {}]
$pos{$g}{$s}{$p}
Truth table0%0/2
A
A= $pos{$g}{$s}{$p}
Aresult
11
00
657 0 ▶ $pos{$g}{$s}{$p}[0]{$o} = 1 if ref $pos{$g}{$s}{$p};
Branch: 1 branch
BranchTrueFalseTotal
if ref $pos{$g}{$s}{$p} 0 0 0
658  
659 0 $patch->add_this($s, $p, $o, $g);
660 }
661 }
662 }
663 else {
664 # forward statement (S P O)
665 0 my ($s, $p);
666 0 ▶ if ($contents{term2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'term2'}) { } 0 0 0
667 0 ($s, $p) = @contents{qw(term1 term2)};
668 }
669 else {
670 0 $s = $self->subject;
671 0 $p = $contents{term1};
672 }
673  
674 # (potentially) rewrite the URI
675 0 ▶ $s = $self->callback->($s) if $self->callback;
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
676  
677 0 ▶ if ($contents{modifier}{'-'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{'modifier'}{'-'}) { } 0 0 0
678 # remove these triples
679 0 ▶ $neg{$g} ||= {};
Condition0%0/2
$neg{$g} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g} ||= {}
$neg{$g}
Truth table0%0/2
A
A= $neg{$g}
Aresult
11
00
680 0 ▶ $neg{$g}{$s} ||= {};
Condition0%0/2
$neg{$g}{$s} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g}{$s} ||= {}
$neg{$g}{$s}
Truth table0%0/2
A
A= $neg{$g}{$s}
Aresult
11
00
681 0 ▶ $neg{$g}{$s}{$p} ||= [{}, {}];
Condition0%0/2
$neg{$g}{$s}{$p} ||= [{}, {}]
l!l
00
MC/DC0%0/1
$neg{$g}{$s}{$p} ||= [{}, {}]
$neg{$g}{$s}{$p}
Truth table0%0/2
A
A= $neg{$g}{$s}{$p}
Aresult
11
00
682  
683 0 ▶ if (@v and ref $neg{$g}{$s}{$p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v and ref $neg{$g}{$s}{$p}) 0 0 0
Condition0%0/3
@v and ref $neg{$g}{$s}{$p}
!ll&&!rl&&r
000
MC/DC0%0/2
@v and ref $neg{$g}{$s}{$p}
@v ref $neg{$g}{$s}{$p}
Truth table0%0/3
A and B
A= @vB= ref $neg{$g}{$s}{$p}
ABresult
0X0
100
111
684 0 for my $o (@v) {
685 # empty string is a wildcard on negated
686 # templates
687 0 ▶ if ($o eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($o eq "") 0 0 0
688 0 $neg{$g}{$s}{$p} = 1;
689 0 $patch->remove_this($s, $p, $o, $g);
690 0 last;
691 }
692  
693 # haha holy shit
694 0 my $d = $contents{designator};
695 0 ▶ if ($d->[0] =~ /[_:]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($d->[0] =~ /[_:]/) { } 0 0 0
elsif ($d->[0] =~ /[\@^]/) { } 0 0 0
696 0 ▶ $o = "_:$o" if $d->[0] eq '_' and $o !~ /^_:/;
Branch: 1 branch
BranchTrueFalseTotal
if $d->[0] eq "_" and not $o =~ /^_:/ 0 0 0
Condition0%0/3
$d->[0] eq "_" and not $o =~ /^_:/
!ll&&!rl&&r
000
MC/DC0%0/2
$d->[0] eq "_" and not $o =~ /^_:/
$d->[0] eq "_" not $o =~ /^_:/
Truth table0%0/3
A and not(B)
A= $d->[0] eq "_"B= not $o =~ /^_:/
ABresult
0X0
100
111
697 0 ▶ my $uri = $self->namespaces->uri($o) || $o;
Condition0%0/3
$self->namespaces->uri($o) || $o
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->namespaces->uri($o) || $o
$self->namespaces->uri($o) $o
Truth table0%0/3
A || B
A= $self->namespaces->uri($o)B= $o
ABresult
1X1
011
000
698 0 ▶ if ($d->[0] eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->[0] eq ":") 0 0 0
699 0 $uri = URI->new_abs($uri, $s);
700 0 ▶ $uri = $self->callback->($uri)
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
701 if $self->callback;
702 }
703 0 $neg{$g}{$s}{$p}[0]{$uri} = 1;
704  
705 0 $o = $uri;
706 }
707 elsif ($d->[0] =~ /[@^]/) {
708 0 my $x = join '', @$d;
709 0 ▶ my $y = $neg{$g}{$s}{$p}[1]{$x} ||= {};
Condition0%0/2
$neg{$g}{$s}{$p}[1]{$x} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g}{$s}{$p}[1]{$x} ||= {}
$neg{$g}{$s}{$p}[1]{$x}
Truth table0%0/2
A
A= $neg{$g}{$s}{$p}[1]{$x}
Aresult
11
00
710 0 $y->{$o} = 1;
711 0 ▶ $o = [$o, $d->[0] eq '@' ?
Branch: 1 branch
BranchTrueFalseTotal
$d->[0] eq '@' ? : 0 0 0
712 $d->[1] : (undef, $d->[1])];
713 }
714 else {
715 0 ▶ my $x = $neg{$g}{$s}{$p}[1]{''} ||= {};
Condition0%0/2
$neg{$g}{$s}{$p}[1]{""} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g}{$s}{$p}[1]{""} ||= {}
$neg{$g}{$s}{$p}[1]{""}
Truth table0%0/2
A
A= $neg{$g}{$s}{$p}[1]{""}
Aresult
11
00
716 0 $x->{$o} = 1;
717 }
718  
719 0 $patch->remove_this($s, $p, $o, $g);
720 }
721 }
722 }
723 else {
724 0 ▶ if ($contents{modifier}{'='}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($contents{"modifier"}{"="}) 0 0 0
725 # remove triple wildcard
726 0 ▶ $neg{$g} ||= {};
Condition0%0/2
$neg{$g} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g} ||= {}
$neg{$g}
Truth table0%0/2
A
A= $neg{$g}
Aresult
11
00
727 0 ▶ $neg{$g}{$s} ||= {};
Condition0%0/2
$neg{$g}{$s} ||= {}
l!l
00
MC/DC0%0/1
$neg{$g}{$s} ||= {}
$neg{$g}{$s}
Truth table0%0/2
A
A= $neg{$g}{$s}
Aresult
11
00
728 0 $neg{$g}{$s}{$p} = 1;
729  
730 0 $patch->remove_this($s, $p, undef, $g);
731 }
732  
733 # add triples
734 0 ▶ $pos{$g} ||= {};
Condition0%0/2
$pos{$g} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g} ||= {}
$pos{$g}
Truth table0%0/2
A
A= $pos{$g}
Aresult
11
00
735 0 ▶ $pos{$g}{$s} ||= {};
Condition0%0/2
$pos{$g}{$s} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g}{$s} ||= {}
$pos{$g}{$s}
Truth table0%0/2
A
A= $pos{$g}{$s}
Aresult
11
00
736 0 ▶ $pos{$g}{$s}{$p} ||= [{}, {}];
Condition0%0/2
$pos{$g}{$s}{$p} ||= [{}, {}]
l!l
00
MC/DC0%0/1
$pos{$g}{$s}{$p} ||= [{}, {}]
$pos{$g}{$s}{$p}
Truth table0%0/2
A
A= $pos{$g}{$s}{$p}
Aresult
11
00
737  
738 0 for my $o (@v) {
739 0 my $d = $contents{designator};
740 0 ▶ if ($d->[0] =~ /[_:]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($d->[0] =~ /[_:]/) { } 0 0 0
elsif ($d->[0] =~ /[\@^]/) { } 0 0 0
741 0 ▶ next if $o eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $o eq "" 0 0 0
742  
743 0 ▶ $o = "_:$o" if $d->[0] eq '_' and $o !~ /^_:/;
Branch: 1 branch
BranchTrueFalseTotal
if $d->[0] eq "_" and not $o =~ /^_:/ 0 0 0
Condition0%0/3
$d->[0] eq "_" and not $o =~ /^_:/
!ll&&!rl&&r
000
MC/DC0%0/2
$d->[0] eq "_" and not $o =~ /^_:/
$d->[0] eq "_" not $o =~ /^_:/
Truth table0%0/3
A and not(B)
A= $d->[0] eq "_"B= not $o =~ /^_:/
ABresult
0X0
100
111
744 0 ▶ my $uri = $self->namespaces->uri($o) || $o;
Condition0%0/3
$self->namespaces->uri($o) || $o
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->namespaces->uri($o) || $o
$self->namespaces->uri($o) $o
Truth table0%0/3
A || B
A= $self->namespaces->uri($o)B= $o
ABresult
1X1
011
000
745 0 ▶ if ($d->[0] eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->[0] eq ":") 0 0 0
746 0 $uri = URI->new_abs($uri, $s);
747 0 ▶ $uri = $self->callback->($uri)
Branch: 1 branch
BranchTrueFalseTotal
if $self->callback 0 0 0
748 if $self->callback;
749 }
750  
751 0 $pos{$g}{$s}{$p}[0]{$uri} = 1;
752  
753 0 $o = $uri;
754 }
755 elsif ($d->[0] =~ /[@^]/) {
756 0 my $x = join '', @$d;
757 0 ▶ my $y = $pos{$g}{$s}{$p}[1]{$x} ||= {};
Condition0%0/2
$pos{$g}{$s}{$p}[1]{$x} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g}{$s}{$p}[1]{$x} ||= {}
$pos{$g}{$s}{$p}[1]{$x}
Truth table0%0/2
A
A= $pos{$g}{$s}{$p}[1]{$x}
Aresult
11
00
758 0 $y->{$o} = 1;
759  
760 0 ▶ $o = [$o,
Branch: 1 branch
BranchTrueFalseTotal
$d->[0] eq '@' ? : 0 0 0
761 $d->[0] eq '@' ? $d->[1] : (undef, $d->[1])];
762 }
763 else {
764 0 ▶ my $x = $pos{$g}{$s}{$p}[1]{''} ||= {};
Condition0%0/2
$pos{$g}{$s}{$p}[1]{""} ||= {}
l!l
00
MC/DC0%0/1
$pos{$g}{$s}{$p}[1]{""} ||= {}
$pos{$g}{$s}{$p}[1]{""}
Truth table0%0/2
A
A= $pos{$g}{$s}{$p}[1]{""}
Aresult
11
00
765 0 $x->{$o} = 1;
766 }
767  
768 0 $patch->add_this($s, $p, $o, $g);
769 }
770 }
771 }
772  
773 # you can tell a blank node from a resource if it starts
774 # with _:
775  
776 # for negative wildcards: { g => { s => { p => 1 } } }
777 # since removing S P * overrides any S P O.
778  
779 # an empty @v means there was no value for this key that
780 # was more than whitespace/empty string.
781  
782  
783 # in this case we probably can't be clever and reuse the
784 # values for multiple templates because some may or may
785 # not include the indicator.
786  
787 # actually we can reuse the values, we just can't parse
788 # them until we've parsed the statement templates, because
789 # those tell us what to do with the values.
790  
791 # which also means we have to parse the statement
792 # templates immediately.
793  
794 # there is still the issue of the empty string: what does
795 # it mean, and in what context?
796  
797 # Step 4.2 dereference macros in statement *values* (that
798 # asked to be)
799  
800  
801 # Step 5: parse statement templates
802  
803 # Step 5.1 expand qnames
804  
805 # Step 6: generate complete statements
806 }
807 }
808  
809 #return [\%neg, \%pos];
810  
811 0 return $patch;
812 }
813  
814 =head1 CAVEATS
815  
816 B<BYOS> == Bring Your Own Security.
817  
818 =head1 AUTHOR
819  
820 Dorian Taylor, C<< <dorian at cpan.org> >>
821  
822 =head1 BUGS
823  
824 Please report any bugs or feature requests to C<bug-rdf-kv at
825 rt.cpan.org>, or through the web interface at
826 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=RDF-KV>. I will be
827 notified, and then you'll automatically be notified of progress on
828 your bug as I make changes.
829  
830 =head1 SUPPORT
831  
832 You can find documentation for this module with the perldoc command.
833  
834 perldoc RDF::KV
835  
836 You can also look for information at:
837  
838 =over 4
839  
840 =item * RT: CPAN's request tracker (report bugs here)
841  
842 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=RDF-KV>
843  
844 =item * AnnoCPAN: Annotated CPAN documentation
845  
846 L<http://annocpan.org/dist/RDF-KV>
847  
848 =item * CPAN Ratings
849  
850 L<http://cpanratings.perl.org/d/RDF-KV>
851  
852 =item * Search CPAN
853  
854 L<http://search.cpan.org/dist/RDF-KV/>
855  
856 =back
857  
858 =head1 SEE ALSO
859  
860 =over 4
861  
862 =item L<RDF::KV::Patch>
863  
864 =item L<URI::BNode>
865  
866 =item L<RDF::Trine>
867  
868 =back
869  
870 =head1 LICENSE AND COPYRIGHT
871  
872 Copyright 2013 Dorian Taylor.
873  
874 Licensed under the Apache License, Version 2.0 (the "License"); you
875 may not use this file except in compliance with the License. You may
876 obtain a copy of the License at
877 L<http://www.apache.org/licenses/LICENSE-2.0>.
878  
879 Unless required by applicable law or agreed to in writing, software
880 distributed under the License is distributed on an "AS IS" BASIS,
881 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
882 implied. See the License for the specific language governing
883 permissions and limitations under the License.
884  
885 =cut
886  
887 2 __PACKAGE__->meta->make_immutable;
888  
889 2 1; # End of RDF::KV
↑ Summary KV/Patch.pm »