blib/lib/RDF/TrineX/Functions.pm

filter: Statementstmt 73.3% 110 / 150 Branchbran 46.8% 45 / 96 Conditioncond 37.9% 55 / 145 MC/DCmcdc 8.9% 7 / 78 Subroutinesub 87.5% 21 / 24 Podpod 100% 5 / 5 totaltotal 48.8% 243 / 498 CC 97 SCAR 47.3
CC
97
Cov
54%
parse
266.1
statement
90.0
__ANON__
70.6
CRAP 113.7
↑ Summary
1 package RDF::TrineX::Functions;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict qw< vars subs >;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 $RDF::TrineX::Functions::AUTHORITY = 'cpan:TOBYINK';
10 3 $RDF::TrineX::Functions::VERSION = '0.005';
11 }
12  
13 3 ▶use Carp qw< croak >;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use IO::Detect 0.003 qw< is_filehandle is_filename is_fileuri >;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use PerlX::Maybe qw< maybe >;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use RDF::NS::Trine;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use RDF::Trine qw< store >;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use RDF::Trine::Namespace qw< rdf rdfs owl xsd >;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Scalar::Util qw< blessed >;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
23 exports => [
24 qw< curie iri blank variable literal statement store model parse >,
25 serialize => \&_build_serializer,
26 ],
27 groups => {
28 nodes => [qw< curie iri blank literal variable >],
29 shortcuts => [
30 parse => { -as => 'rdf_parse' },
31 serialize => { -as => 'rdf_string' },
32 ],
33 shortcuts_nodes => [
34 parse => { -as => 'rdf_parse' },
35 serialize => { -as => 'rdf_string' },
36 iri => { -as => 'rdf_resource' },
37 blank => { -as => 'rdf_blank' },
38 literal => { -as => 'rdf_literal' },
39 variable => { -as => 'rdf_variable' },
40 statement => { -as => 'rdf_statement' },
41 ],
42 },
43 3 };
44  
45 3 foreach my $nodetype (qw< iri blank variable literal >)
46 {
47 my $orig = $nodetype eq 'iri'
48 9 ▶ ? sub { RDF::Trine::Node::Resource->new(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
49 12 ▶ : RDF::Trine->can($nodetype);
Branch: 1 branch
BranchTrueFalseTotal
$nodetype eq 'iri' ? : 3 9 12
50
51 12 my $sub;
52 $sub = sub
53 15 ▶ {
Subroutine __ANON__: called CC=18 SCAR=35.7
54 15 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 15 15
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
1410
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
55 0 ▶ return $sub->(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 15 15
56
57 15 my $node = shift;
58
59 15 ▶ if (blessed($node) and $node->isa('RDF::Trine::Node'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa("RDF::Trine::Node")) 1 14 15
Condition66%2/3
builtin::blessed($node) and $node->isa("RDF::Trine::Node")
!ll&&!rl&&r
1401
MC/DC50%1/2
builtin::blessed($node) and $node->isa("RDF::Trine::Node")
builtin::blessed($node) $node->isa("RDF::Trine::Node")
Truth table66%2/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Trine::Node")
ABresult
0X0
100
111
60 {
61 1 return $node;
62 }
63
64 14 ▶ if ($nodetype eq 'iri' and blessed($node) and $node->isa('URI'))
Branch: 2 branches
BranchTrueFalseTotal
if ($nodetype eq 'iri' and builtin::blessed($node) and $node->isa('URI')) { } 0 14 14
elsif ($nodetype eq 'literal' and builtin::blessed($node) and $node->isa('URI')) { } 0 28 28
Condition50%3/6
$nodetype eq "iri" and builtin::blessed($node) and $node->isa("URI")
!ll&&!rl&&r
1400
$nodetype eq "iri" and builtin::blessed($node)
!ll&&!rl&&r
4100
MC/DC0%0/3
$nodetype eq "iri" and builtin::blessed($node) and $node->isa("URI")
$nodetype eq "iri" builtin::blessed($node) $node->isa("URI")
Truth table50%2/4
A and B and C
A= $nodetype eq "iri"B= builtin::blessed($node)C= $node->isa("URI")
ABCresult
0XX0
10X0
1100
1111
65 {
66 0 return $orig->("$node", @_);
67 }
68 ▶ elsif ($nodetype eq 'literal' and blessed($node) and $node->isa('URI'))
Condition50%3/6
$nodetype eq "literal" and builtin::blessed($node) and $node->isa("URI")
!ll&&!rl&&r
1400
$nodetype eq "literal" and builtin::blessed($node)
!ll&&!rl&&r
1310
MC/DC0%0/3
$nodetype eq "literal" and builtin::blessed($node) and $node->isa("URI")
$nodetype eq "literal" builtin::blessed($node) $node->isa("URI")
Truth table50%2/4
A and B and C
A= $nodetype eq "literal"B= builtin::blessed($node)C= $node->isa("URI")
ABCresult
0XX0
10X0
1100
1111
69 {
70 0 ▶ $_[1] //= $xsd->anyURI unless $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 0 0
Condition0%0/3
$_[1] //= $RDF::TrineX::Functions::xsd->anyURI
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[1] //= $RDF::TrineX::Functions::xsd->anyURI
$_[1] $RDF::TrineX::Functions::xsd->anyURI
Truth table0%0/3
A //= B
A= $_[1]B= $RDF::TrineX::Functions::xsd->anyURI
ABresult
1X1
011
000
71 0 return $orig->("$node", @_);
72 }
73
74 14 ▶ if ($nodetype =~ m[^(iri|blank)$] and $node =~ /^_:(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($nodetype =~ /^(iri|blank)$/ and $node =~ /^_:(.+)$/) 2 12 14
Condition100%3/3
$nodetype =~ /^(iri|blank)$/ and $node =~ /^_:(.+)$/
!ll&&!rl&&r
2102
MC/DC100%2/2
$nodetype =~ /^(iri|blank)$/ and $node =~ /^_:(.+)$/
$nodetype =~ /^(iri|blank)$/ $node =~ /^_:(.+)$/
Truth table100%3/3
A and B
A= $nodetype =~ /^(iri|blank)$/B= $node =~ /^_:(.+)$/
ABresult
0X0
100
111
75 {
76 2 return RDF::Trine::blank($1, @_);
77 }
78
79 12 ▶ if ($nodetype =~ m[^(variable|blank)$] and $node =~ /^\?(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($nodetype =~ /^(variable|blank)$/ and $node =~ /^\?(.+)$/) 2 10 12
Condition66%2/3
$nodetype =~ /^(variable|blank)$/ and $node =~ /^\?(.+)$/
!ll&&!rl&&r
1002
MC/DC50%1/2
$nodetype =~ /^(variable|blank)$/ and $node =~ /^\?(.+)$/
$nodetype =~ /^(variable|blank)$/ $node =~ /^\?(.+)$/
Truth table66%2/3
A and B
A= $nodetype =~ /^(variable|blank)$/B= $node =~ /^\?(.+)$/
ABresult
0X0
100
111
80 {
81 2 return RDF::Trine::variable($1, @_);
82 }
83
84 10 $orig->("$node", @_);
85 12 };
86
87 12 *$nodetype = $sub;
88 }
89  
90 sub new
91 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
92 0 my ($class, @args) = @_;
93 0 bless \@args, $class;
94 }
95  
96 sub curie
97 1 ▶{
Subroutine curie: called CC=9 SCAR=29.0
Pod documented
98 1 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 1 1
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
99 0 ▶ return curie(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 1 1
100
101 1 my $node = shift;
102
103 1 ▶ if (blessed($node) and $node->isa('RDF::Trine::Node'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa("RDF::Trine::Node")) 0 1 1
Condition33%1/3
builtin::blessed($node) and $node->isa("RDF::Trine::Node")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Trine::Node")
builtin::blessed($node) $node->isa("RDF::Trine::Node")
Truth table33%1/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Trine::Node")
ABresult
0X0
100
111
104 {
105 0 return $node;
106 }
107
108 1 ▶ if (blessed($node) and $node->isa('URI'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa("URI")) 0 1 1
Condition33%1/3
builtin::blessed($node) and $node->isa("URI")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($node) and $node->isa("URI")
builtin::blessed($node) $node->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($node)B= $node->isa("URI")
ABresult
0X0
100
111
109 {
110 0 return RDF::Trine::iri("$node", @_);
111 }
112
113 1 ▶ if ($node =~ /^_:(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($node =~ /^_:(.+)$/) 0 1 1
114 {
115 0 return RDF::Trine::blank($1, @_);
116 }
117
118 1 state $ns = RDF::NS::Trine->new('any');
119 1 $ns->URI($node);
120 }
121  
122 sub statement
123 0 ▶{
Subroutine statement: not called CC=9 SCAR=45.0
Pod documented
124 0 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 0 0
Condition0%0/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table0%0/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
125 0 ▶ return statement(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 0 0
126
127 my (@nodes) = map {
128 0 ▶ if (blessed($_) and $_->isa('RDF::Trine::Node')) { $_ }
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($_) and $_->isa('RDF::Trine::Node')) { } 0 0 0
elsif (builtin::blessed($_) and $_->isa('URI')) { } 0 0 0
Condition0%0/3
builtin::blessed($_) and $_->isa("RDF::Trine::Node")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_) and $_->isa("RDF::Trine::Node")
builtin::blessed($_) $_->isa("RDF::Trine::Node")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->isa("RDF::Trine::Node")
ABresult
0X0
100
111
129 0 ▶ elsif (blessed($_) and $_->isa('URI')) { iri($_) }
Condition0%0/3
builtin::blessed($_) and $_->isa("URI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_) and $_->isa("URI")
builtin::blessed($_) $_->isa("URI")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->isa("URI")
ABresult
0X0
100
111
130 0 else { literal($_) }
131 } @_;
132
133 0 ▶ (@nodes==4)
Branch: 1 branch
BranchTrueFalseTotal
@nodes == 4 ? : 0 0 0
134 ? RDF::Trine::Statement::Quad->new(@nodes)
135 : RDF::Trine::Statement->new(@nodes)
136 }
137  
138 sub model
139 6 ▶{
Subroutine model: called CC=7 SCAR=24.4
Pod documented
140 6 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 6 6
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
600
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
141 0 ▶ return model(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 6 6
142
143 6 my $store = shift;
144 6 ▶ return $store if blessed($store) && $store->isa('RDF::Trine::Model');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($store) and $store->isa("RDF::Trine::Model") 0 6 6
Condition33%1/3
builtin::blessed($store) and $store->isa("RDF::Trine::Model")
!ll&&!rl&&r
600
MC/DC0%0/2
builtin::blessed($store) and $store->isa("RDF::Trine::Model")
builtin::blessed($store) $store->isa("RDF::Trine::Model")
Truth table33%1/3
A and B
A= builtin::blessed($store)B= $store->isa("RDF::Trine::Model")
ABresult
0X0
100
111
145
146 6 ▶ $store
Branch: 1 branch
BranchTrueFalseTotal
$store ? : 0 6 6
147 ? RDF::Trine::Model->new($store)
148 : RDF::Trine::Model->new()
149 }
150  
151 sub parse
152 8 ▶{
Subroutine parse: called CC=40 SCAR=55.8
Pod documented
153 8 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 8 8
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
800
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
154 0 ▶ return parse(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 8 8
155
156 8 my ($thing, %opts) = @_;
157
158 8 ▶ my $model = delete($opts{into}) // delete($opts{model});
Condition66%2/3
delete $opts{"into"} // delete $opts{"model"}
l!l&&r!l&&!r
305
MC/DC50%1/2
delete $opts{"into"} // delete $opts{"model"}
delete $opts{"into"} delete $opts{"model"}
Truth table66%2/3
A // B
A= delete $opts{"into"}B= delete $opts{"model"}
ABresult
1X1
011
000
159 8 my $base = delete($opts{base});
160 8 ▶ my $parser = delete($opts{parser}) // delete($opts{type}) // delete($opts{as}) // delete($opts{using});
Condition55%5/9
((delete $opts{"parser"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}
l!l&&r!l&&!r
701
(delete $opts{"parser"} // delete $opts{"type"}) // delete $opts{"as"}
l!l&&r!l&&!r
071
delete $opts{"parser"} // delete $opts{"type"}
l!l&&r!l&&!r
008
MC/DC25%1/4
((delete $opts{"parser"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}
delete $opts{"parser"} delete $opts{"type"} delete $opts{"as"} delete $opts{"using"}
Truth table40%2/5
A // B // C // D
A= delete $opts{"parser"}B= delete $opts{"type"}C= delete $opts{"as"}D= delete $opts{"using"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
161 8 ▶ my $graph = delete($opts{graph}) // delete($opts{context});
Condition66%2/3
delete $opts{"graph"} // delete $opts{"context"}
l!l&&r!l&&!r
305
MC/DC50%1/2
delete $opts{"graph"} // delete $opts{"context"}
delete $opts{"graph"} delete $opts{"context"}
Truth table66%2/3
A // B
A= delete $opts{"graph"}B= delete $opts{"context"}
ABresult
1X1
011
000
162  
163 # Normalise $graph.
164 #
165 8 ▶ $graph = iri($graph) if defined $graph;
Branch: 1 branch
BranchTrueFalseTotal
if defined $graph 3 5 8
166  
167 8 ▶ if (blessed($thing) && $thing->isa('RDF::Trine::Store')
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($thing) and $thing->isa("RDF::Trine::Store") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Model")) 0 8 8
Condition33%3/9
builtin::blessed($thing) and $thing->isa("RDF::Trine::Store") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Model")
l!l&&r!l&&!r
008
builtin::blessed($thing) and $thing->isa("RDF::Trine::Store")
!ll&&!rl&&r
800
builtin::blessed($thing) and $thing->isa("RDF::Trine::Model")
!ll&&!rl&&r
800
MC/DC0%0/4
builtin::blessed($thing) and $thing->isa("RDF::Trine::Store") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Model")
builtin::blessed($thing) $thing->isa("RDF::Trine::Store") builtin::blessed($thing) $thing->isa("RDF::Trine::Model")
Truth table14%1/7
A and B or C and D
A= builtin::blessed($thing)B= $thing->isa("RDF::Trine::Store")C= builtin::blessed($thing)D= $thing->isa("RDF::Trine::Model")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
168 or blessed($thing) && $thing->isa('RDF::Trine::Model'))
169 {
170 0 ▶ return model($thing) unless $model;
Branch: 1 branch
BranchTrueFalseTotal
unless $model 0 0 0
171
172 0 ▶ $thing->as_stream->each(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
173 0 my ($s, $p, $o) = shift->nodes;
174 0 ▶ $model->add_statement(
Branch: 1 branch
BranchTrueFalseTotal
$graph ? : 0 0 0
175 $graph
176 ? statement($s, $p, $o, $graph)
177 : statement($s, $p, $o)
178 );
179 0 });
180 0 return $model;
181 }
182
183 8 ▶ $model //= model();
Condition66%2/3
$model //= model()
l!l&&r!l&&!r
350
MC/DC0%0/2
$model //= model()
$model model()
Truth table66%2/3
A //= B
A= $modelB= model()
ABresult
1X1
011
000
184 8 ▶ return $model unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 1 7 8
185
186 # Normalise $parser. It should be a class name or blessed object.
187 # If undef, then 'RDF::Trine::Parser' class.
188 # If media type then, figure out correct parser.
189 # If format name then, figure out correct parser.
190 #
191 7 ▶ if (not $parser)
Branch: 3 branches
BranchTrueFalseTotal
if (not $parser) { } 0 7 7
elsif (not builtin::blessed($parser) and $parser =~ m[/] and not $parser =~ m[^RDF/]i) { } 0 7 7
elsif (not builtin::blessed($parser)) { } 7 0 7
192 0 { $parser = 'RDF::Trine::Parser' }
193 ▶ elsif (not blessed $parser and $parser =~ m{/} and $parser !~ m{^RDF/}i)
Condition33%2/6
not builtin::blessed($parser) and $parser =~ m[/] and not $parser =~ m[^RDF/]i
!ll&&!rl&&r
700
not builtin::blessed($parser) and $parser =~ m[/]
!ll&&!rl&&r
070
MC/DC0%0/3
not builtin::blessed($parser) and $parser =~ m[/] and not $parser =~ m[^RDF/]i
not builtin::blessed($parser) $parser =~ m[/] not $parser =~ m[^RDF/]i
Truth table25%1/4
not(A) and B and not(C)
A= not builtin::blessed($parser)B= $parser =~ m[/]C= not $parser =~ m[^RDF/]i
ABCresult
0XX0
10X0
1100
1111
194 0 { $parser = RDF::Trine::Parser->parser_by_media_type($parser)->new }
195 elsif (not blessed $parser)
196 7 { $parser = RDF::Trine::Parser->new($parser) }
197  
198 # Normalise $base. Accept RDF::Trine::Nodes.
199 #
200 7 ▶ if (blessed $base and $base->isa('RDF::Trine::Node::Resource'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($base) and $base->isa("RDF::Trine::Node::Resource")) 0 7 7
Condition33%1/3
builtin::blessed($base) and $base->isa("RDF::Trine::Node::Resource")
!ll&&!rl&&r
700
MC/DC0%0/2
builtin::blessed($base) and $base->isa("RDF::Trine::Node::Resource")
builtin::blessed($base) $base->isa("RDF::Trine::Node::Resource")
Truth table33%1/3
A and B
A= builtin::blessed($base)B= $base->isa("RDF::Trine::Node::Resource")
ABresult
0X0
100
111
201 {
202 0 $base = $base->uri;
203 }
204  
205 # Deal with $thing being a URI.
206 # "file://" is explicitly not handled here.
207 #
208 7 ▶ if (blessed($thing) && $thing->isa('URI')
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($thing) and $thing->isa("URI") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource") and $thing = $thing->uri or not builtin::blessed($thing) and $thing =~ /^(https?|ftp|file|data):\S+$/) 0 7 7
Condition33%6/18
builtin::blessed($thing) and $thing->isa("URI") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource") and $thing = $thing->uri or not builtin::blessed($thing) and $thing =~ /^(https?|ftp|file|data):\S+$/
l!l&&r!l&&!r
007
builtin::blessed($thing) and $thing->isa("URI") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource") and $thing = $thing->uri
l!l&&r!l&&!r
007
builtin::blessed($thing) and $thing->isa("URI")
!ll&&!rl&&r
700
builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource") and $thing = $thing->uri
!ll&&!rl&&r
700
builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource")
!ll&&!rl&&r
700
not builtin::blessed($thing) and $thing =~ /^(https?|ftp|file|data):\S+$/
!ll&&!rl&&r
070
MC/DC0%0/7
builtin::blessed($thing) and $thing->isa("URI") or builtin::blessed($thing) and $thing->isa("RDF::Trine::Node::Resource") and $thing = $thing->uri or not builtin::blessed($thing) and $thing =~ /^(https?|ftp|file|data):\S+$/
builtin::blessed($thing) $thing->isa("URI") builtin::blessed($thing) $thing->isa("RDF::Trine::Node::Resource") $thing = $thing->uri not builtin::blessed($thing) $thing =~ /^(https?|ftp|file|data):\S+$/
Truth table4%1/21
A and B or C and D and E or not(F) and G
A= builtin::blessed($thing)B= $thing->isa("URI")C= builtin::blessed($thing)D= $thing->isa("RDF::Trine::Node::Resource")E= $thing = $thing->uriF= not builtin::blessed($thing)G= $thing =~ /^(https?|ftp|file|data):\S+$/
ABCDEFGresult
11XXXXX1
0X111XX1
10111XX1
0X0XX111
0X10X111
0X110111
100XX111
1010X111
10110111
0X0XX0X0
0X0XX100
0X10X0X0
0X10X100
0X1100X0
0X110100
100XX0X0
100XX100
1010X0X0
1010X100
101100X0
10110100
209 or blessed($thing) && $thing->isa('RDF::Trine::Node::Resource') && ($thing = $thing->uri)
210 or !blessed($thing) && $thing =~ m{^(https?|ftp|file|data):\S+$})
211 {
212 0 ▶ if (is_fileuri $thing)
Branch: 2 branches
BranchTrueFalseTotal
if (&is_fileuri($thing)) { } 0 0 0
elsif (not ref $parser and $parser eq 'RDF::Trine::Parser') { } 0 0 0
213 {
214 # Convert to a local path, and allow to fall through...
215 0 URI->new("$thing")->file;
216 }
217 ▶ elsif (not ref $parser and $parser eq 'RDF::Trine::Parser')
Condition0%0/3
not ref $parser and $parser eq "RDF::Trine::Parser"
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $parser and $parser eq "RDF::Trine::Parser"
not ref $parser $parser eq "RDF::Trine::Parser"
Truth table0%0/3
not(A) and B
A= not ref $parserB= $parser eq "RDF::Trine::Parser"
ABresult
0X0
100
111
218 {
219 0 RDF::Trine::Parser->parse_url_into_model(
220 "$thing",
221 $model,
222 maybe context => $graph,
223 );
224 0 return $model;
225 }
226 else
227 {
228 # UA string consistent with RDF::Trine::Parser
229 0 my $ua = LWP::UserAgent->new(agent => "RDF::Trine/$RDF::Trine::VERSION");
230 0 my $resp = $ua->get("$thing");
231 0 ▶ $parser->parse_into_model(
Condition0%0/2
"$base" // "$thing"
l!l
00
MC/DC0%0/1
"$base" // "$thing"
"$base"
Truth table0%0/2
A
A= "$base"
Aresult
11
00
232 ("$base"//"$thing"),
233 $resp->decoded_content,
234 $model,
235 maybe context => $graph,
236 );
237 0 return $model;
238 }
239 }
240
241 # Deal with $thing being a filename.
242 #
243 7 ▶ if (is_filename $thing)
Branch: 1 branch
BranchTrueFalseTotal
if (&is_filename($thing)) 1 6 7
244 {
245 1 ▶ $base //= URI::file->new_abs("$thing");
Condition33%1/3
$base //= "URI::file"->new_abs("$thing")
l!l&&r!l&&!r
100
MC/DC0%0/2
$base //= "URI::file"->new_abs("$thing")
$base "URI::file"->new_abs("$thing")
Truth table33%1/3
A //= B
A= $baseB= "URI::file"->new_abs("$thing")
ABresult
1X1
011
000
246 1 $parser->parse_file_into_model(
247 "$base",
248 "$thing",
249 $model,
250 maybe context => $graph,
251 );
252 1 return $model;
253 }
254
255 6 ▶ croak "No base URI provided" unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $base 0 6 6
256
257 # Deal with $thing being a filehandle (or something similar).
258 #
259 6 ▶ if (is_filehandle $thing)
Branch: 1 branch
BranchTrueFalseTotal
if (&is_filehandle($thing)) 2 4 6
260 {
261 2 $parser->parse_file_into_model(
262 "$base",
263 $thing,
264 $model,
265 maybe context => $graph,
266 );
267 2 return $model;
268 }
269
270 4 ▶ croak "No parser provided for parsing" unless blessed $parser;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($parser) 0 4 4
271 4 $parser->parse_into_model(
272 "$base",
273 $thing,
274 $model,
275 maybe context => $graph,
276 );
277
278 4 return $model;
279 }
280  
281 sub _build_serializer
282 5 ▶{
Subroutine _build_serializer: called CC=1 SCAR=1.3
283 5 my ($class, $name, $arg) = @_;
284
285 5 my $sub;
286 $sub = sub
287 1 ▶ {
Subroutine __ANON__: called CC=18 SCAR=42.6
288 1 ▶ shift if blessed $_[0] && $_[0]->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 0 1 1
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
010
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa(__PACKAGE__)
ABresult
0X0
100
111
289 0 ▶ return $sub->(@{$_[0]}) if ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 1 1
290
291 1 my ($data, %opts) = do {
292 1 ▶ (@_==2)
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 ? : 0 1 1
293 ? ($_[0], as => $_[1])
294 : @_
295 };
296
297 my $ser = delete($opts{serializer})
298 // delete($opts{type})
299 // delete($opts{as})
300 // delete($opts{using})
301 // $arg->{type}
302 // $arg->{-type}
303 1 ▶ // 'Turtle';
Condition35%6/17
(((((delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}) // $arg->{"type"}) // $arg->{"-type"}) // "Turtle"
l!l
10
((((delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}) // $arg->{"type"}) // $arg->{"-type"}
l!l&&r!l&&!r
010
(((delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}) // $arg->{"type"}
l!l&&r!l&&!r
001
((delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}
l!l&&r!l&&!r
001
(delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}
l!l&&r!l&&!r
001
delete $opts{"serializer"} // delete $opts{"type"}
l!l&&r!l&&!r
001
MC/DC0%0/6
(((((delete $opts{"serializer"} // delete $opts{"type"}) // delete $opts{"as"}) // delete $opts{"using"}) // $arg->{"type"}) // $arg->{"-type"}) // "Turtle"
delete $opts{"serializer"} delete $opts{"type"} delete $opts{"as"} delete $opts{"using"} $arg->{"type"} $arg->{"-type"}
Truth table14%1/7
A // B // C // D // E // F
A= delete $opts{"serializer"}B= delete $opts{"type"}C= delete $opts{"as"}D= delete $opts{"using"}E= $arg->{"type"}F= $arg->{"-type"}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
304
305 my $file = delete($opts{to})
306 // delete($opts{file})
307 1 ▶ // delete($opts{output});
Condition33%2/6
(delete $opts{"to"} // delete $opts{"file"}) // delete $opts{"output"}
l!l&&r!l&&!r
001
delete $opts{"to"} // delete $opts{"file"}
l!l&&r!l&&!r
001
MC/DC0%0/3
(delete $opts{"to"} // delete $opts{"file"}) // delete $opts{"output"}
delete $opts{"to"} delete $opts{"file"} delete $opts{"output"}
Truth table25%1/4
A // B // C
A= delete $opts{"to"}B= delete $opts{"file"}C= delete $opts{"output"}
ABCresult
1XX1
01X1
0011
0000
308
309 1 ▶ if (not blessed $ser)
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($ser)) 0 1 1
310 {
311 0 $ser = RDF::Trine::Serializer->new($ser, %opts);
312 }
313
314 1 ▶ if (blessed $data and $data->isa('RDF::Trine::Iterator'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($data) and $data->isa("RDF::Trine::Iterator")) 0 1 1
Condition33%1/3
builtin::blessed($data) and $data->isa("RDF::Trine::Iterator")
!ll&&!rl&&r
010
MC/DC0%0/2
builtin::blessed($data) and $data->isa("RDF::Trine::Iterator")
builtin::blessed($data) $data->isa("RDF::Trine::Iterator")
Truth table33%1/3
A and B
A= builtin::blessed($data)B= $data->isa("RDF::Trine::Iterator")
ABresult
0X0
100
111
315 {
316 0 ▶ return defined($file)
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 0 0 0
317 ? $ser->serialize_iterator_to_file($file, $data)
318 : $ser->serialize_iterator_to_string($data);
319 }
320
321 1 ▶ return defined($file)
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 0 1 1
322 ? $ser->serialize_model_to_file($file, $data)
323 : $ser->serialize_model_to_string($data);
324 }
325 5 }
326  
327 3 *serialize = __PACKAGE__->_build_serializer(serialize => {});
328  
329 3 __PACKAGE__
330 __END__
↑ Summary