RDF/RDB2RDF/DirectMapping/Store.pm

filter: Statementstmt 12.4% 38 / 306 Branchbran 0.0% 0 / 198 Conditioncond 0.0% 0 / 151 MC/DCmcdc 0.0% 0 / 88 Subroutinesub 37.5% 12 / 32 Podpod 61.5% 8 / 13 totaltotal 7.3% 58 / 788 CC 154 SCAR 73.5
CC
154
Cov
6%
get_statements
3906.0
add_statement
992.0
get_pattern
506.0
CRAP 1557.6
↑ Summary RDF/RDB2RDF/DirectMapping/Store/Mixin/SuperGetPattern.pm »
1 package RDF::RDB2RDF::DirectMapping::Store;
2  
3 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Carp qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use RDF::Trine;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Scalar::Util qw[blessed];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use URI::Escape qw[uri_escape uri_unescape];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use match::simple qw[match];
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use base qw[
Subroutine BEGIN: called CC=1 SCAR=0.0
17 RDF::Trine::Store
18 RDF::RDB2RDF::DirectMapping::Store::Mixin::SuperGetPattern
19 5 ];
20  
21 5 our $AUTHORITY = 'cpan:TOBYINK';
22 5 our $VERSION = '0.008';
23  
24 sub new
25 0 ▶{
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
26 0 my $class = shift;
27 0 my $dbh = shift;
28 0 my $mapping = shift;
29 0 ▶ my %options = ref($_[0]) ? %{ +shift } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
30
31 0 my $schema;
32 0 ▶ if (ref $dbh eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dbh eq "ARRAY") 0 0 0
33 {
34 0 ($dbh, $schema) = @$dbh;
35 }
36
37 0 my $layout = $mapping->layout($dbh, $schema);
38 0 foreach my $table (keys %$layout)
39 {
40 0 ▶ unless ($layout->{$table}{keys}
Branch: 1 branch
BranchTrueFalseTotal
unless ($layout->{$table}{"keys"} and grep {$_->{"primary"};} values %{$$layout{$table}{"keys"};}) 0 0 0
Condition0%0/3
$layout->{$table}{"keys"} and grep {$_->{"primary"};} values %{$$layout{$table}{"keys"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$layout->{$table}{"keys"} and grep {$_->{"primary"};} values %{$$layout{$table}{"keys"};}
$layout->{$table}{"keys"} grep {$_->{"primary"};} values %{$$layout{$table}{"keys"};}
Truth table0%0/3
A and B
A= $layout->{$table}{"keys"}B= grep {$_->{"primary"};} values %{$$layout{$table}{"keys"};}
ABresult
0X0
100
111
41 0 and grep { $_->{primary} } values %{$layout->{$table}{keys}})
42 {
43 0 Carp::croak("Table $table lacks a primary key.");
44 }
45 }
46
47 bless {
48 0 dbh => $dbh,
49 schema => $schema,
50 mapping => $mapping,
51 options => \%options,
52 }, $class;
53 }
54  
55 sub _new_with_config
56 0 ▶{
Subroutine _new_with_config: not called CC=5 SCAR=34.0
57 0 my ($class, $config) = @_;
58 0 $config = +{ %$config }; # shallow clone
59
60 my $dbh = DBI->connect(
61 0 ▶ (delete($config->{dsn}) // do { Carp::croak "Need dsn!" }),
Condition0%0/4
delete $config->{"username"} // undef
l!l
00
delete $config->{"password"} // undef
l!l
00
MC/DC0%0/1
delete $config->{"username"} // undef
delete $config->{"username"}
MC/DC0%0/1
delete $config->{"password"} // undef
delete $config->{"password"}
Truth table0%0/2
A
A= delete $config->{"username"}
Aresult
11
00
Truth table0%0/2
A
A= delete $config->{"password"}
Aresult
11
00
62 (delete($config->{username}) // undef),
63 0 ▶ (delete($config->{password}) // undef),
Condition0%0/3
delete $config->{"dsn"} // do { Carp::croak("Need dsn!") }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $config->{"dsn"} // do { Carp::croak("Need dsn!") }
delete $config->{"dsn"} do { Carp::croak("Need dsn!") }
Truth table0%0/3
A // B
A= delete $config->{"dsn"}B= do { Carp::croak("Need dsn!") }
ABresult
1X1
011
000
64 );
65 $dbh = [
66 $dbh,
67 delete($config->{schema}),
68 0 ▶ ] if exists $config->{schema};
Branch: 1 branch
BranchTrueFalseTotal
if exists $config->{"schema"} 0 0 0
69 0 my $mapping = RDF::RDB2RDF::DirectMapping->new(
70 %$config,
71 );
72 0 return $class->new($dbh, $mapping, $config);
73 }
74  
75 0 ▶sub dbh :lvalue { $_[0]->{dbh} }
Subroutine dbh: not called CC=1 SCAR=6.9
Pod undocumented
76 0 ▶sub schema :lvalue { $_[0]->{schema} }
Subroutine schema: not called CC=1 SCAR=6.9
Pod undocumented
77 0 ▶sub mapping :lvalue { $_[0]->{mapping} }
Subroutine mapping: not called CC=1 SCAR=6.9
Pod undocumented
78 0 ▶sub options :lvalue { $_[0]->{options} }
Subroutine options: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 sub get_pattern
81 0 ▶{
Subroutine get_pattern: not called CC=22 SCAR=62.3
Pod documented
82 0 my $self = shift;
83 0 my ($pattern, $context) = @_;
84
85 0 my $NULL = RDF::Trine::Iterator::Bindings->new();
86 0 ▶ return $NULL if blessed($context) && !$context->is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($context) and not $context->is_variable 0 0 0
Condition0%0/3
builtin::blessed($context) and not $context->is_variable
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($context) and not $context->is_variable
builtin::blessed($context) not $context->is_variable
Truth table0%0/3
A and not(B)
A= builtin::blessed($context)B= not $context->is_variable
ABresult
0X0
100
111
87
88 0 ▶ if (scalar $pattern->triples > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar $pattern->triples > 1) 0 0 0
89 {
90 0 my %subjects = map { $_->subject->as_string => $_->subject } $pattern->triples;
91
92 # optimise cases where all subjects are the same
93 0 ▶ if (scalar keys %subjects==1)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %subjects == 1) 0 0 0
94 {
95 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
96 0 my ($subject) = values %subjects;
97 0 my ($table, $where) = (undef, {});
98
99 0 ▶ if ($subject->is_resource)
Branch: 1 branch
BranchTrueFalseTotal
if ($subject->is_resource) { } 0 0 0
100 {
101 0 my ($s_prefix, $s_table, $s_divider, $s_bit) = $self->split_uri($subject);
102
103 0 ▶ if (defined $s_prefix and defined $s_table and $s_divider eq '/' and defined $s_bit)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s_prefix and defined $s_table and $s_divider eq "/" and defined $s_bit) 0 0 0
Condition0%0/9
defined $s_prefix and defined $s_table and $s_divider eq "/" and defined $s_bit
!ll&&!rl&&r
000
defined $s_prefix and defined $s_table and $s_divider eq "/"
!ll&&!rl&&r
000
defined $s_prefix and defined $s_table
!ll&&!rl&&r
000
MC/DC0%0/4
defined $s_prefix and defined $s_table and $s_divider eq "/" and defined $s_bit
defined $s_prefix defined $s_table $s_divider eq "/" defined $s_bit
Truth table0%0/5
A and B and C and D
A= defined $s_prefixB= defined $s_tableC= $s_divider eq "/"D= defined $s_bit
ABCDresult
0XXX0
10XX0
110X0
11100
11111
104 {
105 0 $table = $s_table;
106 0 $where = $self->_handle_bit($table, $s_bit);
107 }
108 }
109 else
110 {
111 0 foreach my $st ($pattern->triples)
112 {
113 0 ▶ return $NULL if $st->object->is_literal and $st->object->has_language;
Branch: 1 branch
BranchTrueFalseTotal
if $st->object->is_literal and $st->object->has_language 0 0 0
Condition0%0/3
$st->object->is_literal and $st->object->has_language
!ll&&!rl&&r
000
MC/DC0%0/2
$st->object->is_literal and $st->object->has_language
$st->object->is_literal $st->object->has_language
Truth table0%0/3
A and B
A= $st->object->is_literalB= $st->object->has_language
ABresult
0X0
100
111
114
115 0 ▶ next unless $st->predicate->is_resource;
Branch: 1 branch
BranchTrueFalseTotal
unless $st->predicate->is_resource 0 0 0
116 0 my ($p_prefix, $p_table, $p_divider, $p_bit) = $self->split_uri($st->predicate);
117  
118 0 ▶ if (defined $p_prefix and defined $p_table and $p_divider eq '#' and defined $p_bit)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p_prefix and defined $p_table and $p_divider eq "#" and defined $p_bit) 0 0 0
Condition0%0/9
defined $p_prefix and defined $p_table and $p_divider eq "#" and defined $p_bit
!ll&&!rl&&r
000
defined $p_prefix and defined $p_table and $p_divider eq "#"
!ll&&!rl&&r
000
defined $p_prefix and defined $p_table
!ll&&!rl&&r
000
MC/DC0%0/4
defined $p_prefix and defined $p_table and $p_divider eq "#" and defined $p_bit
defined $p_prefix defined $p_table $p_divider eq "#" defined $p_bit
Truth table0%0/5
A and B and C and D
A= defined $p_prefixB= defined $p_tableC= $p_divider eq "#"D= defined $p_bit
ABCDresult
0XXX0
10XX0
110X0
11100
11111
119 {
120 0 ▶ $table = $p_table unless defined $table;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $table 0 0 0
121 0 ▶ return $NULL unless $p_table eq $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $p_table eq $table 0 0 0
122
123 my ($column) =
124 0 grep { $p_bit eq $_->{column} }
125 0 @{$layout->{$table}{columns}};
126 0 ▶ return $NULL unless $column;
Branch: 1 branch
BranchTrueFalseTotal
unless $column 0 0 0
127
128 0 ▶ if ($st->object->is_literal)
Branch: 1 branch
BranchTrueFalseTotal
if ($st->object->is_literal) 0 0 0
129 {
130 0 $where->{ $column->{column} } = $st->object->literal_value;
131 }
132 }
133 }
134 }
135
136 #use Data::Dumper;
137 #warn "Can optimise using....\n".Dumper($table,$where);
138
139 0 my $model = RDF::Trine::Model->temporary_model;
140 0 $self->mapping->handle_table([$self->dbh, $self->schema], $model, $table, $where);
141 0 return $model->get_pattern(@_);
142 }
143 }
144
145 0 return $self->_SUPER_get_pattern(@_);
146 }
147  
148 sub get_statements
149 0 ▶{
Subroutine get_statements: not called CC=62 SCAR=82.7
Pod documented
150 0 my ($self, $s, $p, $o, $g) = @_;
151
152 0 ▶ $s = undef if blessed($s) && $s->is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($s) and $s->is_variable 0 0 0
Condition0%0/3
builtin::blessed($s) and $s->is_variable
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($s) and $s->is_variable
builtin::blessed($s) $s->is_variable
Truth table0%0/3
A and B
A= builtin::blessed($s)B= $s->is_variable
ABresult
0X0
100
111
153 0 ▶ $p = undef if blessed($p) && $p->is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($p) and $p->is_variable 0 0 0
Condition0%0/3
builtin::blessed($p) and $p->is_variable
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($p) and $p->is_variable
builtin::blessed($p) $p->is_variable
Truth table0%0/3
A and B
A= builtin::blessed($p)B= $p->is_variable
ABresult
0X0
100
111
154 0 ▶ $o = undef if blessed($o) && $o->is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($o) and $o->is_variable 0 0 0
Condition0%0/3
builtin::blessed($o) and $o->is_variable
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($o) and $o->is_variable
builtin::blessed($o) $o->is_variable
Truth table0%0/3
A and B
A= builtin::blessed($o)B= $o->is_variable
ABresult
0X0
100
111
155 0 ▶ $g = undef if blessed($g) && $g->is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($g) and $g->is_variable 0 0 0
Condition0%0/3
builtin::blessed($g) and $g->is_variable
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($g) and $g->is_variable
builtin::blessed($g) $g->is_variable
Truth table0%0/3
A and B
A= builtin::blessed($g)B= $g->is_variable
ABresult
0X0
100
111
156  
157 0 my $NULL = RDF::Trine::Iterator::Graph->new();
158 0 ▶ return $NULL if $g;
Branch: 1 branch
BranchTrueFalseTotal
if $g 0 0 0
159
160 0 my @results;
161 0 ▶ my $check = RDF::Trine::Statement->new(
Condition0%0/9
$s || 'RDF::Trine::Node::Variable'->new('s')
l!l&&r!l&&!r
000
$p || 'RDF::Trine::Node::Variable'->new('p')
l!l&&r!l&&!r
000
$o || 'RDF::Trine::Node::Variable'->new('o')
l!l&&r!l&&!r
000
MC/DC0%0/2
$s || 'RDF::Trine::Node::Variable'->new('s')
$s 'RDF::Trine::Node::Variable'->new('s')
MC/DC0%0/2
$p || 'RDF::Trine::Node::Variable'->new('p')
$p 'RDF::Trine::Node::Variable'->new('p')
MC/DC0%0/2
$o || 'RDF::Trine::Node::Variable'->new('o')
$o 'RDF::Trine::Node::Variable'->new('o')
Truth table0%0/3
A || B
A= $sB= 'RDF::Trine::Node::Variable'->new('s')
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $pB= 'RDF::Trine::Node::Variable'->new('p')
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $oB= 'RDF::Trine::Node::Variable'->new('o')
ABresult
1X1
011
000
162 $s || RDF::Trine::Node::Variable->new('s'),
163 $p || RDF::Trine::Node::Variable->new('p'),
164 $o || RDF::Trine::Node::Variable->new('o'),
165 );
166 0 ▶ my $callback = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
167 0 ▶ return unless $check->subsumes($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless $check->subsumes($_[0]) 0 0 0
168 0 push @results, $_[0];
169 0 };
170  
171 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
172 0 my ($s_prefix, $s_table, $s_divider, $s_bit) = $self->split_uri($s);
173 0 my ($p_prefix, $p_table, $p_divider, $p_bit) = $self->split_uri($p);
174
175 0 my $table = undef;
176 0 my $where = {};
177 0 my $columns = undef;
178
179 0 ▶ if ($self->mapping->rdfs)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mapping->rdfs) 0 0 0
180 {
181 my $special_namespace = '^' . join '|',
182 0 map { quotemeta($_->uri) } ($RDF, $RDFS, $OWL, $XSD);
183  
184 0 my $check_rdfs = undef;
185  
186 0 ▶ if (blessed($p) and $p->uri =~ /$special_namespace/)
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($p) and $p->uri =~ /$special_namespace/) { } 0 0 0
elsif (builtin::blessed($s) and $s_divider ne '/') { } 0 0 0
Condition0%0/3
builtin::blessed($p) and $p->uri =~ /$special_namespace/
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($p) and $p->uri =~ /$special_namespace/
builtin::blessed($p) $p->uri =~ /$special_namespace/
Truth table0%0/3
A and B
A= builtin::blessed($p)B= $p->uri =~ /$special_namespace/
ABresult
0X0
100
111
187 {
188 0 my ($o_prefix, $o_table, $o_divider);
189 0 ▶ ($o_prefix, $o_table, $o_divider) = $self->split_uri($o)
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($o) and $o->is_resource 0 0 0
Condition0%0/3
builtin::blessed($o) and $o->is_resource
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($o) and $o->is_resource
builtin::blessed($o) $o->is_resource
Truth table0%0/3
A and B
A= builtin::blessed($o)B= $o->is_resource
ABresult
0X0
100
111
190 if blessed($o) && $o->is_resource;
191
192 0 ▶ unless ($p->equal($RDF->type) and $o_prefix)
Branch: 1 branch
BranchTrueFalseTotal
unless ($p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type) and $o_prefix) 0 0 0
Condition0%0/3
$p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type) and $o_prefix
!ll&&!rl&&r
000
MC/DC0%0/2
$p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type) and $o_prefix
$p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type) $o_prefix
Truth table0%0/3
A and B
A= $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)B= $o_prefix
ABresult
0X0
100
111
193 {
194 0 ▶ if ($s_table)
Branch: 2 branches
BranchTrueFalseTotal
if ($s_table) { } 0 0 0
elsif (not defined $s) { } 0 0 0
195 {
196 0 $check_rdfs = $s_table;
197 }
198 elsif (!defined $s)
199 {
200 0 $check_rdfs = '*';
201 }
202 }
203 }
204 ▶ elsif (blessed($s) and $s_divider ne '/')
Condition0%0/3
builtin::blessed($s) and $s_divider ne "/"
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($s) and $s_divider ne "/"
builtin::blessed($s) $s_divider ne "/"
Truth table0%0/3
A and B
A= builtin::blessed($s)B= $s_divider ne "/"
ABresult
0X0
100
111
205 {
206 0 $check_rdfs = $s_table;
207 }
208
209 0 ▶ if ($check_rdfs eq '*')
Branch: 2 branches
BranchTrueFalseTotal
if ($check_rdfs eq '*') { } 0 0 0
elsif (defined $check_rdfs and defined $layout->{$check_rdfs}) { } 0 0 0
210 {
211 $self->mapping->handle_table_rdfs([$self->dbh, $self->schema], $callback, $_)
212 0 foreach keys %$layout;
213 0 return RDF::Trine::Iterator::Graph->new(\@results);
214 }
215 ▶ elsif (defined $check_rdfs and defined $layout->{$check_rdfs})
Condition0%0/3
defined $check_rdfs and defined $layout->{$check_rdfs}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $check_rdfs and defined $layout->{$check_rdfs}
defined $check_rdfs defined $layout->{$check_rdfs}
Truth table0%0/3
A and B
A= defined $check_rdfsB= defined $layout->{$check_rdfs}
ABresult
0X0
100
111
216 {
217 0 $self->mapping->handle_table_rdfs([$self->dbh, $self->schema], $callback, $check_rdfs);
218 0 return RDF::Trine::Iterator::Graph->new(\@results);
219 }
220 }
221
222 # All subject URIs will be prefixed
223 0 ▶ if (defined $s and !$s_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s and not $s_prefix) 0 0 0
Condition0%0/3
defined $s and not $s_prefix
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s and not $s_prefix
defined $s not $s_prefix
Truth table0%0/3
A and not(B)
A= defined $sB= not $s_prefix
ABresult
0X0
100
111
224 {
225 0 return $NULL;
226 }
227  
228 0 ▶ if ($p_prefix)
Branch: 3 branches
BranchTrueFalseTotal
if ($p_prefix) { } 0 0 0
elsif (builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)) { } 0 0 0
elsif (builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::OWL->sameAs)) { } 0 0 0
229 {
230 0 $table = $p_table;
231 0 ▶ return $NULL unless defined $layout->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $layout->{$table} 0 0 0
232
233 # Properties need to be the right type of URI
234 0 ▶ return $NULL
Branch: 1 branch
BranchTrueFalseTotal
unless $p_divider eq "#" 0 0 0
235 unless $p_divider eq '#';
236
237 # TODO: better handling for "ref=".
238 0 ▶ if ($p_bit =~ /^ref=/)
Branch: 1 branch
BranchTrueFalseTotal
if ($p_bit =~ /^ref=/) { } 0 0 0
239 {
240 0 ▶ return $NULL if blessed($o) && $o->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($o) and $o->is_literal 0 0 0
Condition0%0/3
builtin::blessed($o) and $o->is_literal
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($o) and $o->is_literal
builtin::blessed($o) $o->is_literal
Truth table0%0/3
A and B
A= builtin::blessed($o)B= $o->is_literal
ABresult
0X0
100
111
241 }
242 else
243 {
244 # Column needs to exist
245 my ($column) =
246 0 grep { $p_bit eq $_->{column} }
247 0 @{$layout->{$table}{columns}};
248 0 ▶ return $NULL unless $column;
Branch: 1 branch
BranchTrueFalseTotal
unless $column 0 0 0
249 0 $columns = [$column->{column}];
250
251 0 ▶ if (blessed($o))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($o)) 0 0 0
252 {
253 0 ▶ return $NULL unless $o->is_literal;
Branch: 1 branch
BranchTrueFalseTotal
unless $o->is_literal 0 0 0
254 0 ▶ return $NULL if $o->has_language;
Branch: 1 branch
BranchTrueFalseTotal
if $o->has_language 0 0 0
255  
256 0 $where->{ $column->{column} } = $o->literal_value;
257 }
258 }
259 }
260 ▶ elsif (blessed($p) and $p->equal($RDF->type))
Condition0%0/3
builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)
builtin::blessed($p) $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)
Truth table0%0/3
A and B
A= builtin::blessed($p)B= $p->equal($RDF::RDB2RDF::DirectMapping::Store::RDF->type)
ABresult
0X0
100
111
261 {
262 0 my ($o_prefix, $o_table, $o_divider) = $self->split_uri($o);
263 0 ▶ return $NULL unless $o_prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless $o_prefix 0 0 0
264 0 ▶ return $NULL if $o_divider;
Branch: 1 branch
BranchTrueFalseTotal
if $o_divider 0 0 0
265
266 0 $table = $o_table;
267 0 $columns = [];
268 }
269 ▶ elsif (blessed($p) and $p->equal($OWL->sameAs))
Condition0%0/3
builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::OWL->sameAs)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($p) and $p->equal($RDF::RDB2RDF::DirectMapping::Store::OWL->sameAs)
builtin::blessed($p) $p->equal($RDF::RDB2RDF::DirectMapping::Store::OWL->sameAs)
Truth table0%0/3
A and B
A= builtin::blessed($p)B= $p->equal($RDF::RDB2RDF::DirectMapping::Store::OWL->sameAs)
ABresult
0X0
100
111
270 {
271 0 my ($o_prefix, $o_table, $o_divider) = $self->split_uri($o);
272 0 ▶ return $NULL unless $o_prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless $o_prefix 0 0 0
273 0 ▶ return $NULL unless $o_divider eq '/';
Branch: 1 branch
BranchTrueFalseTotal
unless $o_divider eq "/" 0 0 0
274 0 ▶ return $NULL if defined $s_table && $o_table ne $s_table;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s_table and $o_table ne $s_table 0 0 0
Condition0%0/3
defined $s_table and $o_table ne $s_table
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s_table and $o_table ne $s_table
defined $s_table $o_table ne $s_table
Truth table0%0/3
A and B
A= defined $s_tableB= $o_table ne $s_table
ABresult
0X0
100
111
275
276 0 $table = $o_table;
277 }
278  
279 0 ▶ if ($s_prefix)
Branch: 1 branch
BranchTrueFalseTotal
if ($s_prefix) 0 0 0
280 {
281 # Individuals and properties will always belong to the same table
282 0 ▶ return $NULL
Branch: 1 branch
BranchTrueFalseTotal
if defined $table and $s_table ne $table 0 0 0
Condition0%0/3
defined $table and $s_table ne $table
!ll&&!rl&&r
000
MC/DC0%0/2
defined $table and $s_table ne $table
defined $table $s_table ne $table
Truth table0%0/3
A and B
A= defined $tableB= $s_table ne $table
ABresult
0X0
100
111
283 if defined $table && $s_table ne $table;
284  
285 0 ▶ $table ||= $s_table;
Condition0%0/3
$table ||= $s_table
l!l&&r!l&&!r
000
MC/DC0%0/2
$table ||= $s_table
$table $s_table
Truth table0%0/3
A ||= B
A= $tableB= $s_table
ABresult
1X1
011
000
286 0 ▶ return $NULL unless defined $layout->{$table};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $layout->{$table} 0 0 0
287  
288 # Individuals need to be the right type of URI
289 0 ▶ return $NULL
Branch: 1 branch
BranchTrueFalseTotal
unless $s_divider eq "/" 0 0 0
290 unless $s_divider eq '/';
291  
292 # Needs to be some conditions to identify the individual.
293 0 my $conditions = $self->_handle_bit($table, $s_bit);
294 0 ▶ return $NULL unless $conditions;
Branch: 1 branch
BranchTrueFalseTotal
unless $conditions 0 0 0
295  
296 # Add conditions to $where
297 0 ▶ while (my ($k, $v) = each %$conditions)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$conditions) 0 0 0
298 {
299 # Conflicting conditions
300 0 ▶ if (defined $where->{$k} and $where->{$k} ne $v)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $where->{$k} and $where->{$k} ne $v) 0 0 0
Condition0%0/3
defined $where->{$k} and $where->{$k} ne $v
!ll&&!rl&&r
000
MC/DC0%0/2
defined $where->{$k} and $where->{$k} ne $v
defined $where->{$k} $where->{$k} ne $v
Truth table0%0/3
A and B
A= defined $where->{$k}B= $where->{$k} ne $v
ABresult
0X0
100
111
301 {
302 0 return $NULL;
303 }
304 0 $where->{$k} = $v;
305 }
306 }
307  
308 0 ▶ $where = undef unless keys %$where;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$where 0 0 0
309
310 0 ▶ if ($table)
Branch: 1 branch
BranchTrueFalseTotal
if ($table) { } 0 0 0
311 {
312 #use Data::Dumper;
313 #warn ("Saved Time!\n".Dumper($table , $where));
314 0 $self->mapping->handle_table([$self->dbh, $self->schema], $callback, $table, $where, $columns);
315 }
316 else
317 {
318 0 $self->mapping->process([$self->dbh, $self->schema], $callback);
319 }
320
321 0 return RDF::Trine::Iterator::Graph->new(\@results);
322 }
323  
324 sub _handle_bit
325 0 ▶{
Subroutine _handle_bit: not called CC=3 SCAR=24.8
326 0 my ($self, $table, $bit) = @_;
327
328 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
329 0 my ($pkey) = grep { $_->{primary} } values %{$layout->{$table}{keys}};
330
331 my $regex =
332 join '\;',
333 0 map { sprintf('%s=(.*)', quotemeta(_uri_escape($_))) }
334 0 @{$pkey->{columns}};
335
336 # warn "'$bit' =~ /$regex/";
337
338 0 ▶ if (my @values = ($bit =~ /^ $regex $/x))
Branch: 1 branch
BranchTrueFalseTotal
if (my(@values) = $bit =~ /^ $regex $/x) 0 0 0
339 {
340 0 my $r = {};
341 0 ▶ for (my $i=0; exists $values[$i]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $values[$i]) 0 0 0
342 {
343 0 $r->{ $pkey->{columns}[$i] } = uri_unescape($values[$i]);
344 }
345 0 return $r;
346 }
347
348 0 return;
349 }
350  
351 sub _uri_escape
352 0 ▶{
Subroutine _uri_escape: not called CC=1 SCAR=6.9
353 0 my $s = uri_escape(shift);
354 0 $s =~ s/\+/%20/g;
355 0 $s;
356 }
357  
358 sub split_uri
359 0 ▶{
Subroutine split_uri: not called CC=4 SCAR=30.0
Pod undocumented
360 0 my ($self, $uri) = @_;
361 0 ▶ return unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 0 0
362 0 ▶ $uri = $uri->uri if blessed($uri);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($uri) 0 0 0
363
364 0 my $prefix = $self->mapping->prefix;
365 0 ▶ if ($uri =~ m!^ (\Q$prefix\E) # prefix
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ m[^ (\Q$prefix\E) # prefix ([^#/]+) # table name (?: # optionally... ([#/]) # URI divider (.+) # other bit )? $]x) 0 0 0
366 ([^#/]+) # table name
367 (?: # optionally...
368 ([#/]) # URI divider
369 (.+) # other bit
370 )? $!x)
371 {
372 0 return ($1, $2, $3, $4);
373 }
374
375 0 return;
376 }
377  
378 sub get_contexts
379 0 ▶{
Subroutine get_contexts: not called CC=1 SCAR=6.9
Pod documented
380 0 return RDF::Trine::Iterator->new();
381 }
382  
383 sub count_statements
384 0 ▶{
Subroutine count_statements: not called CC=2 SCAR=17.9
Pod documented
385 0 my $self = shift;
386 0 my $iter = $self->get_statements(@_);
387 0 my $count = 0;
388 0 ▶ while (my $st = $iter->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
389 {
390 0 $count++;
391 }
392 0 return $count;
393 }
394  
395 sub add_statement
396 0 ▶{
Subroutine add_statement: not called CC=31 SCAR=69.0
Pod documented
397 0 my ($self, $st, $ctxt, $opt) = @_;
398
399 my %merged = (
400 0 %{ $self->options },
401 %$opt,
402 );
403 0 local $self->{options} = \%merged;
404
405 0 ▶ if ($ctxt or $st->can('context') && $st->context)
Branch: 1 branch
BranchTrueFalseTotal
if ($ctxt or $st->can("context") and $st->context) 0 0 0
Condition0%0/6
$ctxt or $st->can("context") and $st->context
l!l&&r!l&&!r
000
$st->can("context") and $st->context
!ll&&!rl&&r
000
MC/DC0%0/3
$ctxt or $st->can("context") and $st->context
$ctxt $st->can("context") $st->context
Truth table0%0/4
A or B and C
A= $ctxtB= $st->can("context")C= $st->context
ABCresult
1XX1
0111
00X0
0100
406 {
407 0 $self->_carp(
408 add => $st,
409 "this store does not accept quads; treating as a triple",
410 );
411 }
412
413 0 my $already = $self->get_statements(
414 $st->subject,
415 $st->predicate,
416 $st->object,
417 );
418 0 ▶ return if $already->next;
Branch: 1 branch
BranchTrueFalseTotal
if $already->next 0 0 0
419  
420 return $self->_croak(
421 add => $st,
422 "contains blank node",
423 0 ▶ ) if grep { $_->is_blank } (
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->is_blank;} $st->subject, $st->predicate, $st->object 0 0 0
424 $st->subject,
425 $st->predicate,
426 $st->object,
427 );
428  
429 0 my ($s_prefix, $s_table, $s_divider, $s_bit) = $self->split_uri($st->subject);
430 0 my ($p_prefix, $p_table, $p_divider, $p_bit) = $self->split_uri($st->predicate);
431  
432 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s_prefix and defined $p_prefix and $s_prefix eq $p_prefix 0 0 0
Condition0%0/6
defined $s_prefix and defined $p_prefix and $s_prefix eq $p_prefix
!ll&&!rl&&r
000
defined $s_prefix and defined $p_prefix
!ll&&!rl&&r
000
MC/DC0%0/3
defined $s_prefix and defined $p_prefix and $s_prefix eq $p_prefix
defined $s_prefix defined $p_prefix $s_prefix eq $p_prefix
Truth table0%0/4
A and B and C
A= defined $s_prefixB= defined $p_prefixC= $s_prefix eq $p_prefix
ABCresult
0XX0
10X0
1100
1111
433 add => $st,
434 "subject and predicate are not contained within this database according to mapping",
435 )
436 unless defined $s_prefix
437 && defined $p_prefix
438 && $s_prefix eq $p_prefix;
439
440 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s_table and defined $p_table and $s_table eq $p_table 0 0 0
Condition0%0/6
defined $s_table and defined $p_table and $s_table eq $p_table
!ll&&!rl&&r
000
defined $s_table and defined $p_table
!ll&&!rl&&r
000
MC/DC0%0/3
defined $s_table and defined $p_table and $s_table eq $p_table
defined $s_table defined $p_table $s_table eq $p_table
Truth table0%0/4
A and B and C
A= defined $s_tableB= defined $p_tableC= $s_table eq $p_table
ABCresult
0XX0
10X0
1100
1111
441 add => $st,
442 "subject and predicate not from matching tables",
443 )
444 unless defined $s_table
445 && defined $p_table
446 && $s_table eq $p_table;
447
448 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
if match($s_table, $self->mapping->ignore_tables) 0 0 0
449 add => $st,
450 "table $s_table is ignored by mapping",
451 )
452 if match $s_table, $self->mapping->ignore_tables;
453
454 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s_divider and $s_divider eq "/" 0 0 0
Condition0%0/3
defined $s_divider and $s_divider eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $s_divider and $s_divider eq "/"
defined $s_divider $s_divider eq "/"
Truth table0%0/3
A and B
A= defined $s_dividerB= $s_divider eq "/"
ABresult
0X0
100
111
455 add => $st,
456 "subject not a 'slash URI'",
457 )
458 unless defined $s_divider
459 && $s_divider eq '/';
460  
461 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p_divider and $p_divider eq "#" 0 0 0
Condition0%0/3
defined $p_divider and $p_divider eq "#"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p_divider and $p_divider eq "#"
defined $p_divider $p_divider eq "#"
Truth table0%0/3
A and B
A= defined $p_dividerB= $p_divider eq "#"
ABresult
0X0
100
111
462 add => $st,
463 "predicate not a 'hash URI'",
464 )
465 unless defined $p_divider
466 && $p_divider eq '#';
467  
468 0 ▶ if ($st->object->is_literal)
Branch: 1 branch
BranchTrueFalseTotal
if ($st->object->is_literal) { } 0 0 0
469 {
470 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
if defined $p_bit and $p_bit =~ /^ref=/ 0 0 0
Condition0%0/3
defined $p_bit and $p_bit =~ /^ref=/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p_bit and $p_bit =~ /^ref=/
defined $p_bit $p_bit =~ /^ref=/
Truth table0%0/3
A and B
A= defined $p_bitB= $p_bit =~ /^ref=/
ABresult
0X0
100
111
471 add => $st,
472 "predicate has non-literal range, but object is literal",
473 )
474 if defined $p_bit
475 && $p_bit =~ /^ref=/;
476
477 0 ▶ return $self->_carp(
Branch: 1 branch
BranchTrueFalseTotal
if $st->object->has_language 0 0 0
478 add => $st,
479 "literal language ignored",
480 )
481 if $st->object->has_language;
482
483 0 ▶ my $table = $self->schema ? sprintf('%s.%s', $self->schema, $p_table) : $p_table ;
Branch: 1 branch
BranchTrueFalseTotal
$self->schema ? : 0 0 0
484 0 my $index = $self->_handle_bit($s_table, $s_bit);
485 0 my $column = $p_bit;
486 0 my $value = $st->object->literal_value;
487 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
488
489 return $self->_croak(
490 add => $st,
491 "table $table has no column $column",
492 )
493 0 unless grep { $_->{column} eq $column }
494 0 ▶ @{ $layout->{$table}{columns} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->{"column"} eq $column;} @{$$layout{$table}{"columns"};} 0 0 0
495
496 my $sth = $self->dbh->prepare(sprintf(
497 'SELECT CASE WHEN %s IS NULL THEN 1 ELSE 2 END AS x FROM %s WHERE %s',
498 $column,
499 $table,
500 0 join(q[ AND ] => map { "$_=?" } sort keys %$index)
501 ));
502 0 $sth->execute(map { $index->{$_} } sort keys %$index);
503  
504 0 ▶ if (my($r) = $sth->fetchrow_array)
Branch: 1 branch
BranchTrueFalseTotal
if (my($r) = $sth->fetchrow_array) { } 0 0 0
505 {
506 0 ▶ if ($r==2
Branch: 1 branch
BranchTrueFalseTotal
if ($r == 2 and defined $self->options->{"overwrite"} and not $self->options->{"overwrite"}) 0 0 0
Condition0%0/6
$r == 2 and defined $self->options->{"overwrite"} and not $self->options->{"overwrite"}
!ll&&!rl&&r
000
$r == 2 and defined $self->options->{"overwrite"}
!ll&&!rl&&r
000
MC/DC0%0/3
$r == 2 and defined $self->options->{"overwrite"} and not $self->options->{"overwrite"}
$r == 2 defined $self->options->{"overwrite"} not $self->options->{"overwrite"}
Truth table0%0/4
A and B and not(C)
A= $r == 2B= defined $self->options->{"overwrite"}C= not $self->options->{"overwrite"}
ABCresult
0XX0
10X0
1100
1111
507 and defined $self->options->{overwrite}
508 and not $self->options->{overwrite})
509 {
510 0 return $self->_carp(
511 add => $st,
512 "will not overwrite existing value",
513 );
514 }
515
516 my $sth = $self->dbh->prepare(sprintf(
517 'UPDATE %s SET %s=? WHERE %s',
518 $table,
519 $column,
520 0 join(q[ AND ] => map { "$_=?" } sort keys %$index)
521 ));
522 0 ▶ $sth->execute($value, map { $index->{$_} } sort keys %$index)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($value, map({$index->{$_};} sort(keys %$index))) or $self->_croak("add", $st, "could not UPDATE database") 0 0 0
523 or $self->_croak(add => $st, "could not UPDATE database");
524 0 return;
525 }
526 else
527 {
528 my $sth = $self->dbh->prepare(sprintf(
529 'INSERT INTO %s (%s, %s) VALUES (?, %s)',
530 $table,
531 $column,
532 join(q[, ] => sort keys %$index),
533 0 join(q[, ] => map { ;'?' } keys %$index),
534 ));
535 0 ▶ $sth->execute($value, map { $index->{$_} } sort keys %$index)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($value, map({$index->{$_};} sort(keys %$index))) or $self->_croak("add", $st, "could not INSERT into database") 0 0 0
536 or $self->_croak(add => $st, "could not INSERT into database");
537 0 return;
538 }
539 }
540 else
541 {
542 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
if defined $p_bit and not $p_bit =~ /^ref=/ 0 0 0
Condition0%0/3
defined $p_bit and not $p_bit =~ /^ref=/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p_bit and not $p_bit =~ /^ref=/
defined $p_bit not $p_bit =~ /^ref=/
Truth table0%0/3
A and not(B)
A= defined $p_bitB= not $p_bit =~ /^ref=/
ABresult
0X0
100
111
543 add => $st,
544 "predicate has literal range, but non-literal value",
545 )
546 if defined $p_bit
547 && $p_bit !~ /^ref=/;
548
549 0 return $self->_croak(
550 add => $st,
551 "non-literal objects not implemented yet",
552 );
553 }
554 }
555  
556 sub remove_statement
557 0 ▶{
Subroutine remove_statement: not called CC=13 SCAR=52.0
Pod documented
558 0 my ($self, $st, $ctxt, $opt) = @_;
559
560 my %merged = (
561 0 %{ $self->options },
562 %$opt,
563 );
564 0 local $self->{options} = \%merged;
565
566 0 ▶ if ($ctxt or $st->can('context') && $st->context)
Branch: 1 branch
BranchTrueFalseTotal
if ($ctxt or $st->can("context") and $st->context) 0 0 0
Condition0%0/6
$ctxt or $st->can("context") and $st->context
l!l&&r!l&&!r
000
$st->can("context") and $st->context
!ll&&!rl&&r
000
MC/DC0%0/3
$ctxt or $st->can("context") and $st->context
$ctxt $st->can("context") $st->context
Truth table0%0/4
A or B and C
A= $ctxtB= $st->can("context")C= $st->context
ABCresult
1XX1
0111
00X0
0100
567 {
568 0 $self->_carp(
569 remove => $st,
570 "this store does not accept quads; treating as a triple",
571 );
572 }
573
574 0 my $already = $self->get_statements(
575 $st->subject,
576 $st->predicate,
577 $st->object,
578 );
579 0 ▶ return unless $already->next;
Branch: 1 branch
BranchTrueFalseTotal
unless $already->next 0 0 0
580  
581 0 my ($s_prefix, $s_table, $s_divider, $s_bit) = $self->split_uri($st->subject);
582 0 my ($p_prefix, $p_table, $p_divider, $p_bit) = $self->split_uri($st->predicate);
583  
584 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s_table and defined $p_table and $s_table eq $p_table 0 0 0
Condition0%0/6
defined $s_table and defined $p_table and $s_table eq $p_table
!ll&&!rl&&r
000
defined $s_table and defined $p_table
!ll&&!rl&&r
000
MC/DC0%0/3
defined $s_table and defined $p_table and $s_table eq $p_table
defined $s_table defined $p_table $s_table eq $p_table
Truth table0%0/4
A and B and C
A= defined $s_tableB= defined $p_tableC= $s_table eq $p_table
ABCresult
0XX0
10X0
1100
1111
585 remove => $st,
586 "subject and predicate not from matching tables",
587 )
588 unless defined $s_table
589 && defined $p_table
590 && $s_table eq $p_table;
591
592 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
if match($s_table, $self->mapping->ignore_tables) 0 0 0
593 remove => $st,
594 "table $s_table is ignored by mapping",
595 )
596 if match $s_table, $self->mapping->ignore_tables;
597
598 0 ▶ if ($st->object->is_literal)
Branch: 1 branch
BranchTrueFalseTotal
if ($st->object->is_literal) { } 0 0 0
599 {
600 0 ▶ my $table = $self->schema ? sprintf('%s.%s', $self->schema, $p_table) : $p_table ;
Branch: 1 branch
BranchTrueFalseTotal
$self->schema ? : 0 0 0
601 0 my $index = $self->_handle_bit($s_table, $s_bit);
602 0 my $column = $p_bit;
603 0 my $value = $st->object->literal_value;
604 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
605
606 0 ▶ if (exists $index->{$column})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index->{$column}) 0 0 0
607 {
608 0 return $self->_croak(
609 remove => $st,
610 "column $column is part of table primary key",
611 );
612 }
613
614 my $sth = $self->dbh->prepare(sprintf(
615 'UPDATE %s SET %s=NULL WHERE %s=? AND %s',
616 $table,
617 $column,
618 $column,
619 0 join(q[ AND ] => map { "$_=?" } sort keys %$index)
620 ));
621 0 ▶ $sth->execute($value, map { $index->{$_} } sort keys %$index)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute($value, map({$index->{$_};} sort(keys %$index))) or $self->_croak("remove", $st, "could not UPDATE database") 0 0 0
622 or $self->_croak(remove => $st, "could not UPDATE database");
623 0 return;
624 }
625 else
626 {
627 0 return $self->_croak(
628 remove => $st,
629 "non-literal objects not implemented yet",
630 );
631 }
632 }
633  
634 sub remove_statements
635 0 ▶{
Subroutine remove_statements: not called CC=10 SCAR=47.0
Pod documented
636 0 my $self = shift;
637 0 my ($s, $p, $o) = @_;
638
639 # catch the special case of
640 # $store->remove_statements($s, undef, undef)
641 # and use it to delete an entire row from the table
642 0 ▶ if ($s and !$p and !$o and $s->is_resource)
Branch: 1 branch
BranchTrueFalseTotal
if ($s and not $p and not $o and $s->is_resource) 0 0 0
Condition0%0/9
$s and not $p and not $o and $s->is_resource
!ll&&!rl&&r
000
$s and not $p and not $o
!ll&&!rl&&r
000
$s and not $p
!ll&&!rl&&r
000
MC/DC0%0/4
$s and not $p and not $o and $s->is_resource
$s not $p not $o $s->is_resource
Truth table0%0/5
A and not(B) and not(C) and D
A= $sB= not $pC= not $oD= $s->is_resource
ABCDresult
0XXX0
10XX0
110X0
11100
11111
643 {
644 0 my ($s_prefix, $s_table, $s_divider, $s_bit) = $self->split_uri($s);
645
646 # for error messages
647 0 ▶ my $st = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
648 0 RDF::Trine::Statement->new(
649 $s,
650 RDF::Trine::Node::Variable->new('any_predicate'),
651 RDF::Trine::Node::Variable->new('any_object'),
652 )
653 0 };
654
655 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s_prefix 0 0 0
656 remove => $st,
657 "subject not contained within this database according to mapping",
658 )
659 unless defined $s_prefix;
660
661 0 ▶ return $self->_croak(
Branch: 1 branch
BranchTrueFalseTotal
if match($s_table, $self->mapping->ignore_tables) 0 0 0
662 remove => $st->(),
663 "table $s_table is ignored by mapping",
664 )
665 if match $s_table, $self->mapping->ignore_tables;
666
667 0 ▶ my $table = $self->schema ? sprintf('%s.%s', $self->schema, $s_table) : $s_table ;
Branch: 1 branch
BranchTrueFalseTotal
$self->schema ? : 0 0 0
668 0 my $index = $self->_handle_bit($s_table, $s_bit);
669 0 my $layout = $self->mapping->layout($self->dbh, $self->schema);
670
671 my $sth = $self->dbh->prepare(sprintf(
672 'DELETE FROM %s WHERE %s',
673 $table,
674 0 join(q[ AND ] => map { "$_=?" } sort keys %$index)
675 ));
676 0 ▶ $sth->execute(map { $index->{$_} } sort keys %$index)
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(map({$index->{$_};} sort(keys %$index))) or $self->_croak("remove", &$st(), "could not DELETE FROM database") 0 0 0
677 or $self->_croak(remove => $st->(), "could not DELETE FROM database");
678 0 return;
679 }
680
681 0 my $iter = $self->get_statements(@_);
682 0 ▶ while (my $st = $iter->next)
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
683 {
684 0 $self->remove_statement($st);
685 }
686 }
687  
688 sub _carp
689 0 ▶{
Subroutine _carp: not called CC=3 SCAR=24.8
690 0 my ($self, $method, $st, $message) = @_;
691
692 0 ▶ if (exists $self->options->{on_carp})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->options->{'on_carp'}) { } 0 0 0
693 {
694 $self->options->{on_carp}->(@_)
695 0 ▶ if ref $self->options->{on_carp} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->options->{"on_carp"} eq "CODE" 0 0 0
696 }
697 else
698 {
699 0 Carp::carp(sprintf("Warning for %s %s: %s", $method, $st->sse, $message));
700 }
701 }
702  
703 sub _croak
704 0 ▶{
Subroutine _croak: not called CC=3 SCAR=24.8
705 0 my ($self, $method, $st, $message) = @_;
706
707 0 ▶ if (exists $self->options->{on_croak})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->options->{'on_croak'}) { } 0 0 0
708 {
709 $self->options->{on_croak}->(@_)
710 0 ▶ if ref $self->options->{on_croak} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->options->{"on_croak"} eq "CODE" 0 0 0
711 }
712 else
713 {
714 0 Carp::croak(sprintf("Cannot %s %s: %s", $method, $st->sse, $message));
715 }
716 }
717  
718 5 1;
719  
720 __END__
↑ Summary RDF/RDB2RDF/DirectMapping/Store/Mixin/SuperGetPattern.pm »