RDF/RDB2RDF/DirectMapping.pm

filter: Statementstmt 18.0% 47 / 261 Branchbran 0.0% 0 / 106 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 40.5% 15 / 37 Podpod 33.3% 5 / 15 totaltotal 14.4% 67 / 465 CC 75 SCAR 53.2
CC
75
Cov
12%
handle_table
552.0
layout
382.5
handle_table_rdfs
110.0
CRAP 204.9
« RDF/RDB2RDF/DirectMapping/Store/Mixin/SuperGetPattern.pm ↑ Summary RDF/RDB2RDF/DatatypeMapper.pm »
1 package RDF::RDB2RDF::DirectMapping;
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[carp croak];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use MIME::Base64 qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use RDF::Trine qw[iri blank literal statement];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use RDF::Trine::Namespace qw[RDF RDFS OWL XSD];
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Scalar::Util qw[refaddr blessed];
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use URI::Escape::Optimistic qw[uri_escape_optimistic];
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use match::simple qw[match];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use base qw[
Subroutine BEGIN: called CC=1 SCAR=0.0
19 RDF::RDB2RDF
20 RDF::RDB2RDF::DatatypeMapper
21 5 ];
22  
23 5 our $AUTHORITY = 'cpan:TOBYINK';
24 5 our $VERSION = '0.008';
25  
26 sub new
27 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
28 0 my ($class, %args) = @_;
29
30 0 ▶ $args{prefix} = '' unless defined $args{prefix};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"prefix"} 0 0 0
31 0 ▶ $args{rdfs} = 0 unless defined $args{rdfs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"rdfs"} 0 0 0
32 0 ▶ $args{warn_sql} = 0 unless defined $args{warn_sql};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"warn_sql"} 0 0 0
33 0 ▶ $args{ignore_tables} = [] unless defined $args{ignore_tables};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"ignore_tables"} 0 0 0
34 0 $args{unique} = Data::UUID->new->create_str;
35
36 0 bless \%args, $class;
37 }
38  
39 0 ▶sub prefix :lvalue { $_[0]->{prefix} }
Subroutine prefix: not called CC=1 SCAR=6.9
Pod documented
40 0 ▶sub rdfs :lvalue { $_[0]->{rdfs} }
Subroutine rdfs: not called CC=1 SCAR=6.9
Pod undocumented
41 0 ▶sub ignore_tables :lvalue { $_[0]->{ignore_tables} }
Subroutine ignore_tables: not called CC=1 SCAR=6.9
Pod undocumented
42 0 ▶sub warn_sql :lvalue { $_[0]->{warn_sql} }
Subroutine warn_sql: not called CC=1 SCAR=6.9
Pod undocumented
43  
44 sub _unquote_identifier
45 0 ▶{
Subroutine _unquote_identifier: not called CC=2 SCAR=17.9
46 0 my $i = shift;
47 0 ▶ return $1 if $i =~ /^\"(.+)\"$/;
Branch: 1 branch
BranchTrueFalseTotal
if $i =~ /^\"(.+)\"$/ 0 0 0
48 0 return $i;
49 }
50  
51 sub rowmap (&$)
52 0 ▶{
Subroutine rowmap: not called CC=4 SCAR=30.0
Pod undocumented
53 0 my ($coderef, $iter) = @_;
54
55 0 my @results = ();
56 0 ▶ ref($iter) or return @results;
Branch: 1 branch
BranchTrueFalseTotal
ref $iter or return @results 0 0 0
57
58 0 local $_;
59 0 my $i = 0;
60 0 ▶ while ($_ = $iter->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = $iter->fetchrow_hashref) 0 0 0
61 {
62 0 push @results, $coderef->($coderef, $iter, $_, ++$i);
63 }
64
65 0 ▶ wantarray ? @results : scalar(@results);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
66 }
67  
68 sub layout
69 0 ▶{
Subroutine layout: not called CC=20 SCAR=59.5
Pod undocumented
70 0 my ($self, $dbh, $schema) = @_;
71  
72 0 ▶ unless ($self->{layout}{refaddr($dbh).'|'.$schema})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"layout"}{builtin::refaddr($dbh) . '|' . $schema}) 0 0 0
73 {
74 0 ▶ carp sprintf('READ SCHEMA "%s"', $schema||'%') if $self->warn_sql;
Branch: 1 branch
BranchTrueFalseTotal
if $self->warn_sql 0 0 0
Condition0%0/2
$schema || '%'
l!l
00
MC/DC0%0/1
$schema || '%'
$schema
Truth table0%0/2
A
A= $schema
Aresult
11
00
75
76 0 my $rv = {};
77 0 ▶ my @tables = rowmap {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 _unquote_identifier($_->{TABLE_NAME})
79 0 } $dbh->table_info(undef, $schema, undef, undef);
80  
81 0 foreach my $table (@tables)
82 {
83 0 ▶ if ($table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i) 0 0 0
Condition0%0/3
$table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i
!ll&&!rl&&r
000
MC/DC0%0/2
$table =~ /^sqlite_/ and $dbh->get_info(17) =~ /sqlite/i
$table =~ /^sqlite_/ $dbh->get_info(17) =~ /sqlite/i
Truth table0%0/3
A and B
A= $table =~ /^sqlite_/B= $dbh->get_info(17) =~ /sqlite/i
ABresult
0X0
100
111
84 {
85 0 next;
86 }
87
88 0 ▶ $rv->{$table}{columns} ||= [];
Condition0%0/2
$rv->{$table}{"columns"} ||= []
l!l
00
MC/DC0%0/1
$rv->{$table}{"columns"} ||= []
$rv->{$table}{"columns"}
Truth table0%0/2
A
A= $rv->{$table}{"columns"}
Aresult
11
00
89 0 ▶ $rv->{$table}{keys} ||= {};
Condition0%0/2
$rv->{$table}{"keys"} ||= {}
l!l
00
MC/DC0%0/1
$rv->{$table}{"keys"} ||= {}
$rv->{$table}{"keys"}
Truth table0%0/2
A
A= $rv->{$table}{"keys"}
Aresult
11
00
90 0 ▶ $rv->{$table}{refs} ||= {};
Condition0%0/2
$rv->{$table}{"refs"} ||= {}
l!l
00
MC/DC0%0/1
$rv->{$table}{"refs"} ||= {}
$rv->{$table}{"refs"}
Truth table0%0/2
A
A= $rv->{$table}{"refs"}
Aresult
11
00
91
92 5 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 $rv->{$table}{columns} = [
94 0 sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} }
95 0 ▶ rowmap {
Subroutine __ANON__: not called CC=3 SCAR=24.8
96 my $type = ($_->{TYPE_NAME} =~ /^char$/i and defined $_->{COLUMN_SIZE})
97 ? sprintf('%s(%d)', $_->{TYPE_NAME}, $_->{COLUMN_SIZE})
98 0 ▶ : $_->{TYPE_NAME};
Branch: 1 branch
BranchTrueFalseTotal
$_->{'TYPE_NAME'} =~ /^char$/i && defined $_->{'COLUMN_SIZE'} ? : 0 0 0
Condition0%0/3
$_->{"TYPE_NAME"} =~ /^char$/i and defined $_->{"COLUMN_SIZE"}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"TYPE_NAME"} =~ /^char$/i and defined $_->{"COLUMN_SIZE"}
$_->{"TYPE_NAME"} =~ /^char$/i defined $_->{"COLUMN_SIZE"}
Truth table0%0/3
A and B
A= $_->{"TYPE_NAME"} =~ /^char$/iB= defined $_->{"COLUMN_SIZE"}
ABresult
0X0
100
111
99 +{
100 column => _unquote_identifier($_->{COLUMN_NAME}),
101 type => $type,
102 order => $_->{ORDINAL_POSITION},
103 nullable => $_->{NULLABLE},
104 }
105 0 }
106 0 $dbh->column_info(undef, $schema, $table, undef)
107 ];
108
109 0 my $pkey_name;
110 my @pkey_cols =
111 map {
112 0 $pkey_name = _unquote_identifier($_->{PK_NAME});
113 0 _unquote_identifier($_->{COLUMN_NAME});
114 }
115 0 sort { $a->{KEY_SEQ} <=> $b->{KEY_SEQ} }
116 0 ▶ rowmap {
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 0 +{ %$_ };
118 }
119 0 $dbh->primary_key_info(undef, $schema, $table, undef);
120
121 0 ▶ $rv->{$table}{keys}{$pkey_name} = {
Branch: 1 branch
BranchTrueFalseTotal
if @pkey_cols 0 0 0
122 name => $pkey_name,
123 columns => \@pkey_cols,
124 primary => 1,
125 } if @pkey_cols;
126  
127 0 my $sth = $dbh->foreign_key_info(undef, $schema, undef, undef, $schema, $table);
128 0 ▶ if ($sth)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 0 0 0
129 {
130 0 my @r;
131 0 ▶ while (my $result = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $sth->fetchrow_hashref) 0 0 0
132 {
133 0 push @r, $result;
134 }
135 0 @r = sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} } @r;
136 0 foreach my $f (@r)
137 {
138 0 push @{ $rv->{$table}{refs}{ $f->{FK_NAME} }{columns} }, _unquote_identifier($f->{FK_COLUMN_NAME});
139 0 push @{ $rv->{$table}{refs}{ $f->{FK_NAME} }{target_columns} }, _unquote_identifier($f->{UK_COLUMN_NAME});
140 0 $rv->{$table}{refs}{ $f->{FK_NAME} }{target_table} = _unquote_identifier($f->{UK_TABLE_NAME});
141 }
142 }
143
144 0 $sth = $dbh->statistics_info(undef, $schema, $table, 1, 0);
145 0 ▶ if ($sth)
Branch: 1 branch
BranchTrueFalseTotal
if ($sth) 0 0 0
146 {
147 0 my @r;
148 0 ▶ while (my $result = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $result = $sth->fetchrow_hashref) 0 0 0
149 {
150 0 ▶ next if $result->{FILTER_CONDITION};
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"FILTER_CONDITION"} 0 0 0
151 0 ▶ next if $result->{NON_UNIQUE};
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"NON_UNIQUE"} 0 0 0
152 0 ▶ next if $rv->{$table}{keys}{ _unquote_identifier($result->{INDEX_NAME}) };
Branch: 1 branch
BranchTrueFalseTotal
if $rv->{$table}{"keys"}{_unquote_identifier($result->{"INDEX_NAME"})} 0 0 0
153 0 push @r, $result;
154 }
155 0 @r = sort { $a->{ORDINAL_POSITION} <=> $b->{ORDINAL_POSITION} } @r;
156 0 foreach my $f (@r)
157 {
158 0 push @{ $rv->{$table}{keys}{ $f->{INDEX_NAME} }{columns} }, _unquote_identifier($f->{COLUMN_NAME});
159 0 $rv->{$table}{keys}{ $f->{INDEX_NAME} }{name} = _unquote_identifier($f->{INDEX_NAME});
160 }
161 }
162 }
163  
164 0 $self->{layout}{refaddr($dbh).'|'.$schema} = $rv;
165 }
166  
167 0 $self->{layout}{refaddr($dbh).'|'.$schema};
168 }
169  
170 sub process
171 0 ▶{
Subroutine process: not called CC=5 SCAR=34.0
Pod documented
172 0 my ($self, $dbh, $model) = @_;
173
174 0 ▶ $model = RDF::Trine::Model->temporary_model unless defined $model;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model 0 0 0
175 my $callback = (ref $model eq 'CODE')
176 ? $model
177 0 ▶ : sub{ $model->add_statement(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $model eq 'CODE' ? : 0 0 0
178 0 my $schema;
179 0 ▶ ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $dbh eq 'ARRAY' ? : 0 0 0
180  
181 0 my $layout = $self->layout($dbh, $schema);
182 0 foreach my $table (keys %$layout)
183 {
184 0 $table =~ s/^"(.+)"$/$1/;
185 0 $self->handle_table([$dbh, $schema], $callback, $table);
186 }
187
188 0 return $model;
189 }
190  
191 sub handle_table
192 0 ▶{
Subroutine handle_table: not called CC=23 SCAR=63.1
Pod documented
193 0 my ($self, $dbh, $model, $table, $where, $cols) = @_;
194 0 ▶ return if match $table, $self->ignore_tables;
Branch: 1 branch
BranchTrueFalseTotal
if match($table, $self->ignore_tables) 0 0 0
195
196 0 ▶ $model = RDF::Trine::Model->temporary_model unless defined $model;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model 0 0 0
197 0 ▶ my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $model eq 'CODE' ? : 0 0 0
198 0 my $schema;
199 0 ▶ ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $dbh eq 'ARRAY' ? : 0 0 0
200 0 ▶ $cols = [$cols] if (defined $cols and !ref $cols and length $cols);
Branch: 1 branch
BranchTrueFalseTotal
if defined $cols and not ref $cols and length $cols 0 0 0
Condition0%0/6
defined $cols and not ref $cols and length $cols
!ll&&!rl&&r
000
defined $cols and not ref $cols
!ll&&!rl&&r
000
MC/DC0%0/3
defined $cols and not ref $cols and length $cols
defined $cols not ref $cols length $cols
Truth table0%0/4
A and not(B) and C
A= defined $colsB= not ref $colsC= length $cols
ABCresult
0XX0
10X0
1100
1111
201
202 0 my $layout = $self->layout($dbh, $schema);
203
204 0 ▶ if (ref $cols eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY') { } 0 0 0
205 {
206 0 my ($pkey) = grep { $_->{primary} } values %{ $layout->{$table}{keys} };
207 0 my %cols = map { $_ => 1 } (@{ $pkey->{columns} }, @$cols);
208 0 $cols = join ',', map { $dbh->quote_identifier($_) } sort keys %cols;
209 }
210 else
211 {
212 0 $cols = '*';
213 }
214  
215 0 ▶ $self->handle_table_rdfs([$dbh, $schema], $callback, $table)
Branch: 1 branch
BranchTrueFalseTotal
if $cols eq "*" and not defined $where 0 0 0
Condition0%0/3
$cols eq "*" and not defined $where
!ll&&!rl&&r
000
MC/DC0%0/2
$cols eq "*" and not defined $where
$cols eq "*" not defined $where
Truth table0%0/3
A and not(B)
A= $cols eq "*"B= not defined $where
ABresult
0X0
100
111
216 if ($cols eq '*' and !defined $where);
217  
218 0 ▶ my $sql = $schema
Branch: 1 branch
BranchTrueFalseTotal
$schema ? : 0 0 0
219 ? sprintf('SELECT %s FROM %s.%s', $cols, $dbh->quote_identifier($schema), $dbh->quote_identifier($table))
220 : sprintf('SELECT %s FROM %s', $cols, $dbh->quote_identifier($table));
221
222 0 my @values;
223 0 ▶ if ($where)
Branch: 1 branch
BranchTrueFalseTotal
if ($where) 0 0 0
224 {
225 0 my @w;
226 0 ▶ while (my ($k,$v) = each %$where)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$where) 0 0 0
227 {
228 0 push @w, sprintf('%s = ?', $dbh->quote_identifier($k));
229 0 push @values, $v;
230 }
231 0 $sql .= ' WHERE ' . (join ' AND ', @w);
232 }
233  
234 0 ▶ carp($sql) if $self->warn_sql;
Branch: 1 branch
BranchTrueFalseTotal
if $self->warn_sql 0 0 0
235 0 my $sth = $dbh->prepare($sql);
236 0 $sth->execute(@values);
237
238 0 ▶ while (my $row = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
239 {
240 # use Data::Dumper;
241 # print Dumper($layout, $row, $table);
242 my ($pkey_uri) =
243 0 map { $self->make_key_uri($table, $_->{columns}, $row); }
244 sort {
245 $b->{primary} <=> $a->{primary}
246 or $a->{name} cmp $b->{name}
247 0 ▶ }
Condition0%0/3
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
Truth table0%0/3
A || B
A= $RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}B= $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
ABresult
1X1
011
000
248 0 values %{ $layout->{$table}{keys} };
249 0 ▶ my $subject = $pkey_uri ? iri($pkey_uri) : blank();
Branch: 1 branch
BranchTrueFalseTotal
$pkey_uri ? : 0 0 0
250
251 # rdf:type
252 0 $callback->(statement($subject, $RDF->type, iri($self->prefix.$table)));
253
254 # owl:sameAs
255 0 ▶ if ($cols eq '*')
Branch: 1 branch
BranchTrueFalseTotal
if ($cols eq "*") 0 0 0
256 {
257 $callback->(statement($subject, $OWL->sameAs, $_))
258 0 foreach
259 0 grep { not $subject->equal($_) }
260 0 map { iri $_ } # don't combine with previous step, as make_key_uri can return empty list
261 0 map { $self->make_key_uri($table, $_->{columns}, $row) }
262 0 values %{ $layout->{$table}{keys} };
263 }
264
265 # p-o for columns
266 0 foreach my $column (@{ $layout->{$table}{columns} })
267 {
268 0 ▶ next unless defined $row->{ $column->{column} };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$row{$column->{"column"}} 0 0 0
269
270 0 my $predicate = iri($self->prefix.$table.'#'.$column->{column});
271 my $object = $self->datatyped_literal(
272 $row->{ $column->{column} },
273 $column->{type},
274 0 );
275 0 $callback->(statement($subject, $predicate, $object));
276 }
277
278 # foreign keys
279 0 foreach my $ref (values %{ $layout->{$table}{refs} })
280 {
281 0 my $predicate = iri($self->make_ref_uri($table, $ref));
282 0 my $object = iri($self->make_ref_dest_uri($table, $ref, $row, [$dbh, $schema]));
283 0 $callback->(statement($subject, $predicate, $object));
284 }
285 }
286 }
287  
288 sub handle_table_rdfs
289 0 ▶{
Subroutine handle_table_rdfs: not called CC=10 SCAR=47.0
Pod undocumented
290 0 my ($self, $dbh, $model, $table) = @_;
291 0 ▶ return if match $table, $self->ignore_tables;
Branch: 1 branch
BranchTrueFalseTotal
if match($table, $self->ignore_tables) 0 0 0
292
293 0 ▶ $model = RDF::Trine::Model->temporary_model unless defined $model;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model 0 0 0
294 0 ▶ my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $model eq 'CODE' ? : 0 0 0
295 0 my $schema;
296 0 ▶ ($dbh, $schema) = ref($dbh) eq 'ARRAY' ? @$dbh : ($dbh, undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $dbh eq 'ARRAY' ? : 0 0 0
297  
298 0 my $layout = $self->layout($dbh, $schema);
299  
300 0 ▶ if ($self->rdfs)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rdfs) 0 0 0
301 {
302 0 $callback->(statement(iri($self->prefix.$table), $RDF->type, $OWL->Class));
303 0 $callback->(statement(iri($self->prefix.$table), $RDFS->label, literal($table)));
304  
305 0 foreach my $column (@{ $layout->{$table}{columns} })
306 {
307 0 my $predicate = iri($self->prefix.$table.'#'.$column->{column});
308 0 my $dummy = $self->datatyped_literal('DUMMY', $column->{type});
309 0 ▶ my $datatype = $dummy->has_datatype ? iri($dummy->literal_datatype) : $RDFS->Literal;
Branch: 1 branch
BranchTrueFalseTotal
$dummy->has_datatype ? : 0 0 0
310
311 0 $callback->(statement($predicate, $RDF->type, $OWL->DatatypeProperty));
312 0 $callback->(statement($predicate, $RDFS->label, literal($column->{column})));
313 0 $callback->(statement($predicate, $RDFS->domain, iri($self->prefix.$table)));
314 0 ▶ $callback->(statement($predicate, $RDFS->range, $datatype)) if $datatype;
Branch: 1 branch
BranchTrueFalseTotal
if $datatype 0 0 0
315 }
316
317 0 foreach my $ref (values %{ $layout->{$table}{refs} })
318 {
319 0 my $predicate = iri($self->make_ref_uri($table, $ref));
320 0 $callback->(statement($predicate, $RDF->type, $OWL->ObjectProperty));
321 0 $callback->(statement($predicate, $RDFS->domain, iri($self->prefix.$table)));
322 0 $callback->(statement($predicate, $RDFS->range, iri($self->prefix.$ref->{target_table})));
323 }
324 }
325 }
326  
327 sub process_turtle
328 0 ▶{
Subroutine process_turtle: not called CC=1 SCAR=6.9
Pod documented
329 0 my ($self, @args) = @_;
330 0 return $self->SUPER::process_turtle(@args, base_uri=>$self->prefix);
331 }
332  
333 sub make_key_uri
334 0 ▶{
Subroutine make_key_uri: not called CC=2 SCAR=17.9
Pod undocumented
335 0 my ($self, $table, $columns, $data) = @_;
336
337 0 ▶ return if grep { !defined $data->{$_} } @$columns;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $data->{$_};} @$columns 0 0 0
338
339 return $self->prefix .
340 uri_escape_optimistic($table) . "/" .
341 (join ';', map
342 0 { sprintf('%s=%s', uri_escape_optimistic($_), uri_escape_optimistic($data->{$_})); }
343 @$columns);
344 }
345  
346 sub make_ref_uri
347 0 ▶{
Subroutine make_ref_uri: not called CC=1 SCAR=6.9
Pod undocumented
348 0 my ($self, $table, $ref) = @_;
349
350 return $self->prefix .
351 uri_escape_optimistic($table) . "#ref-" .
352 (join ';', map
353 0 { uri_escape_optimistic($_); }
354 0 @{$ref->{columns}});
355 }
356  
357 sub make_ref_dest_uri_OLD
358 0 ▶{
Subroutine make_ref_dest_uri_OLD: not called CC=2 SCAR=17.9
Pod undocumented
359 0 my ($self, $table, $ref, $data) = @_;
360
361 0 my $map;
362 0 ▶ for (my $i = 0; exists $ref->{columns}[$i]; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{"columns"}[$i]) 0 0 0
363 {
364 0 $map->{ $ref->{target_columns}[$i] } = $ref->{columns}[$i];
365 }
366
367 return $self->prefix .
368 uri_escape_optimistic($ref->{target_table}) . "/" .
369 (join ';', map
370 0 { sprintf('%s=%s', uri_escape_optimistic($_), uri_escape_optimistic($data->{$map->{$_}})); }
371 0 @{$ref->{target_columns}});
372 }
373  
374 sub make_ref_dest_uri
375 0 ▶{
Subroutine make_ref_dest_uri: not called CC=9 SCAR=45.0
Pod undocumented
376 0 my ($self, $table, $ref, $data, $dbh) = @_;
377
378 0 my $schema;
379 0 ▶ ($dbh, $schema) = @$dbh if ref $dbh eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dbh eq "ARRAY" 0 0 0
380 0 my $layout = $self->layout($dbh, $schema);
381  
382 my %cols =
383 0 map { $_ => 1 }
384 0 map { @{ $_->{columns} } }
385 0 values %{ $layout->{ $ref->{target_table} }{keys} };
386 my $cols =
387 join q[, ],
388 0 map { $dbh->quote_identifier($_) }
389 sort keys %cols;
390 my $sql = $schema
391 ? sprintf('SELECT %s FROM %s.%s', $cols, $dbh->quote_identifier($schema), $dbh->quote_identifier($ref->{target_table}))
392 0 ▶ : sprintf('SELECT %s FROM %s', $cols, $dbh->quote_identifier($ref->{target_table}));
Branch: 1 branch
BranchTrueFalseTotal
$schema ? : 0 0 0
393
394 0 my @values;
395 my @where;
396 0 foreach my $i (0 .. @{$ref->{target_columns}}-1)
397 {
398 0 ▶ if (defined $data->{ $ref->{columns}[$i] })
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$data{$ref->{'columns'}[$i]}) { } 0 0 0
399 {
400 0 push @where, sprintf('%s = ?', $dbh->quote_identifier($ref->{target_columns}[$i]));
401 0 push @values, $data->{ $ref->{columns}[$i] };
402 }
403 else
404 {
405 0 push @where, sprintf('%s IS NULL', $dbh->quote_identifier($ref->{target_columns}[$i]));
406 }
407 }
408 0 $sql .= ' WHERE ' . (join ' AND ', @where);
409  
410 0 ▶ carp($sql) if $self->warn_sql;
Branch: 1 branch
BranchTrueFalseTotal
if $self->warn_sql 0 0 0
411 0 my $sth = $dbh->prepare($sql);
412 0 $sth->execute(@values);
413  
414 0 ▶ if (my $row = $sth->fetchrow_hashref)
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
415 {
416 my ($pkey_uri) =
417 0 map { $self->make_key_uri($ref->{target_table}, $_->{columns}, $row); }
418 sort {
419 $b->{primary} <=> $a->{primary}
420 or $a->{name} cmp $b->{name}
421 0 ▶ }
Condition0%0/3
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} || $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
$RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'} $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
Truth table0%0/3
A || B
A= $RDF::RDB2RDF::DirectMapping::b->{'primary'} <=> $RDF::RDB2RDF::DirectMapping::a->{'primary'}B= $RDF::RDB2RDF::DirectMapping::a->{'name'} cmp $RDF::RDB2RDF::DirectMapping::b->{'name'}
ABresult
1X1
011
000
422 0 values %{ $layout->{$ref->{target_table}}{keys} };
423
424 0 ▶ return $pkey_uri if $pkey_uri;
Branch: 1 branch
BranchTrueFalseTotal
if $pkey_uri 0 0 0
425 }
426  
427 0 $self->make_ref_dest_uri_OLD($table, $ref, $data);
428 }
429  
430 5 1;
431  
432 __END__
« RDF/RDB2RDF/DirectMapping/Store/Mixin/SuperGetPattern.pm ↑ Summary RDF/RDB2RDF/DatatypeMapper.pm »