| 1 | package RDF::RDB2RDF::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 Digest::MD5 qw[md5_hex]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use JSON qw[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use overload qw[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use RDF::Trine qw[statement blank literal]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use RDF::Trine::Namespace qw[rdf rdfs owl xsd]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Scalar::Util qw[blessed]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use URI::Escape::Optimistic qw[uri_escape_optimistic]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use base qw[ | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | RDF::RDB2RDF | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | RDF::RDB2RDF::DatatypeMapper | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | our $VERSION = '0.008'; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | my ($class, %mappings) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | my $ns = delete($mappings{-namespaces}) // +{}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $mappings{"-namespaces"} // {}
MC/DC0%0/1
delete $mappings{"-namespaces"} // {}
delete $mappings{"-namespaces"}
Truth table50%1/2
A
A= delete $mappings{"-namespaces"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | my $base = delete($mappings{-base}) // 'http://example.com/base/'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $mappings{"-base"} // "http://example.com/base/"
MC/DC0%0/1
delete $mappings{"-base"} // "http://example.com/base/"
delete $mappings{"-base"}
Truth table50%1/2
A
A= delete $mappings{"-base"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | while (my ($k, $v) = each %$ns) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $ns->{$k} = RDF::Trine::Namespace->new($v) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($v) and $v->isa("RDF::Trine::Namespace")
MC/DC0%0/2
builtin::blessed($v) and $v->isa("RDF::Trine::Namespace")
builtin::blessed($v)
$v->isa("RDF::Trine::Namespace")
Truth table0%0/3
A and B
A= builtin::blessed($v)B= $v->isa("RDF::Trine::Namespace")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | unless (blessed($v) and $v->isa('RDF::Trine::Namespace')); | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | bless { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | mappings => \%mappings, | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | namespaces => $ns, | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | base => $base, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | sub mappings | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 40 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mappings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 40 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 40 | return $self->{mappings}; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub namespaces | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespaces: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my %NS; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | %NS = %{ $self->{namespaces} } | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | if (ref $self->{namespaces} eq 'HASH' or blessed($self->{namespaces})); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self->{"namespaces"} eq "HASH" or builtin::blessed($self->{"namespaces"})
MC/DC0%0/2
ref $self->{"namespaces"} eq "HASH" or builtin::blessed($self->{"namespaces"})
ref $self->{"namespaces"} eq "HASH"
builtin::blessed($self->{"namespaces"})
Truth table33%1/3
A or B
A= ref $self->{"namespaces"} eq "HASH"B= builtin::blessed($self->{"namespaces"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | %NS = ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | owl => "$owl", | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | rdf => "$rdf", | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | rdfs => "$rdfs", | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | xsd => "$xsd", | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ) unless %NS; | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | return %NS; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sub template | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template: called CC=13 SCAR=29.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | my ($self, $template, $data, $types, $process) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $process = sub { +shift } unless ref $process eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 19 | ▶ | if (blessed($template) and $template->isa('RDF::Trine::Node')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($template) and $template->isa("RDF::Trine::Node")
MC/DC0%0/2
builtin::blessed($template) and $template->isa("RDF::Trine::Node")
builtin::blessed($template)
$template->isa("RDF::Trine::Node")
Truth table66%2/3
A and B
A= builtin::blessed($template)B= $template->isa("RDF::Trine::Node")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return $template; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 19 | ▶ | if (blessed($template) and $template->isa('RDF::RDB2RDF::R2RML::_COL_')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($template) and $template->isa("RDF::RDB2RDF::R2RML::_COL_")
MC/DC50%1/2
builtin::blessed($template) and $template->isa("RDF::RDB2RDF::R2RML::_COL_")
builtin::blessed($template)
$template->isa("RDF::RDB2RDF::R2RML::_COL_")
Truth table66%2/3
A and B
A= builtin::blessed($template)B= $template->isa("RDF::RDB2RDF::R2RML::_COL_")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my $col = substr($template, 1, -1); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | return $data->{$col}; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | $self->{uuid} = Data::UUID->new unless $self->{uuid}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | $data->{'+uuid'} = $self->{uuid}->create_str; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | $template =~ s( | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | (?<!\\) \{ # opening unescaped brace | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ( # start capturing | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | (?: \\\} | [^}] )+ # escaped closing braces and non-brace characters | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ) # finish capturing | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | \} # closing brace | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | (my $key = $1) | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | =~ s/\\\}/\}/g; | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | my ($value, $type); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | ▶ | if ($key =~ /^"(.+)"$/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $value = ($data->{$1}); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $type = ($types->{$1} // 'varchar'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$types->{$1} // "varchar"
MC/DC0%0/1
$types->{$1} // "varchar"
$types->{$1}
Truth table0%0/2
A
A= $types->{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | $value = ($data->{$key} // $data->{lc $key}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$data->{$key} // $$data{lc $key}
MC/DC0%0/2
$data->{$key} // $$data{lc $key}
$data->{$key}
$$data{lc $key}
Truth table33%1/3
A // B
A= $data->{$key}B= $$data{lc $key}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | ▶ | $type = ($types->{$key} // $types->{lc $key} // ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($types->{$key} // $$types{lc $key}) // ""
$types->{$key} // $$types{lc $key}
MC/DC0%0/2
($types->{$key} // $$types{lc $key}) // ""
$types->{$key}
$$types{lc $key}
Truth table33%1/3
A // B
A= $types->{$key}B= $$types{lc $key}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | return unless defined $value; # Argh! return in a regexp! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | $process->( $self->datatyped_literal($value, $type)->literal_value ); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | }gex; | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | $template =~ s< \\ ( [{}\\] ) >< $1 >xg; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 16 | return $template; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub template_irisafe | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template_irisafe: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 19 | template(@_, \&URI::Escape::Optimistic::uri_escape_optimistic); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub iri | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 49 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iri: called CC=7 SCAR=26.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 49 | my ($self, $iri, $graph) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 49 | ▶ | unless defined $iri; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 48 | ▶ | return $iri | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($iri) and $iri->isa("RDF::Trine::Node")
MC/DC0%0/2
builtin::blessed($iri) and $iri->isa("RDF::Trine::Node")
builtin::blessed($iri)
$iri->isa("RDF::Trine::Node")
Truth table33%1/3
A and B
A= builtin::blessed($iri)B= $iri->isa("RDF::Trine::Node")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | if blessed($iri) && $iri->isa('RDF::Trine::Node'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 48 | ▶ | return blank() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | if $iri eq '[]'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 48 | ▶ | if ($iri =~ /^_:(.*)$/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $ident = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $ident =~ s/([^0-9A-Za-wyz])/sprintf('x%04X', ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($graph) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $ident = md5_hex("$graph").$ident; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return blank($ident); | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 48 | return RDF::Trine::Node::Resource->new("$iri", $self->{base}); | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | sub process | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | my ($self, $dbh, $model) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | my $callback = (ref $model eq 'CODE') | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | ? $model | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | ▶ | : sub { $model->add_statement(@_) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | my $mappings = $self->mappings; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | TABLE: foreach my $table (keys %$mappings) | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | $self->handle_table($dbh, $callback, $table); | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | return $model; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub _mktemplate | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mktemplate: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $string =~ s! ( [\\{}] ) !\\$1!gx; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub _get_types | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_types: called CC=3 SCAR=11.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 5 | my ($self, $sth, $dbh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 5 | my %types; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 5 | ▶ | if (exists $sth->{pg_type}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # For PostgreSQL, this appears to give better results. | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Particularly in the case of columns which don't exist | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # in the table itself. (e.g. aggregation, casting, | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # functions, etc) | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | @types{ @{$sth->{NAME}} } = | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | @{ $sth->{pg_type} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | {eval{ | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 5 | @types{ @{$sth->{NAME}} } = | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | /^\d+$/ | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ? scalar($dbh->type_info($_)->{TYPE_NAME}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 22 | ▶ | : $_ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | @{ $sth->{TYPE} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | }} | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | return \%types; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | sub handle_table | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_table: called CC=21 SCAR=43.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | my ($self, $dbh, $model, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | my $mappings = $self->mappings; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | my $tmap = $mappings->{$table}; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # ->{from} | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | ▶ | my $from = $tmap->{from} || $table; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$tmap->{'from'} || $table
MC/DC0%0/2
$tmap->{'from'} || $table
$tmap->{'from'}
$table
Truth table66%2/3
A || B
A= $tmap->{'from'}B= $table
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # ->{select} | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | ▶ | my $select = $tmap->{select} || '*'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tmap->{'select'} || '*'
MC/DC0%0/1
$tmap->{'select'} || '*'
$tmap->{'select'}
Truth table50%1/2
A
A= $tmap->{'select'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # ->{sql} | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my $sql = "SELECT $select FROM $from"; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | $sql = $tmap->{sql} if $tmap->{sql};# =~ /^\s*SELECT/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ### Re-jig mapping structure. | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | $tmap->{-maps} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | $tmap->{-jmaps} = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | my %c = %{$tmap->{columns}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | ▶ | while (my ($col, $list) = each %c) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 7 | push @{ $tmap->{-maps} }, | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | map { {%$_, column => $col}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 7 | grep { !defined $_->{join} } | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | @$list; | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | push @{ $tmap->{-jmaps} }, | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | grep { defined $_->{join} } | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | @$list; | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ▶ | my $sth = $dbh->prepare($sql) or return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | my $types = $self->_get_types($sth, $dbh); | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | my $row_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | ▶ | ROW: while (my $row = $sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 15 | $row_count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | 15 | $self->handle_row($dbh, $callback, $table, $row, $types, $row_count); | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | JMAP: foreach my $map (@{ $tmap->{-jmaps} }) | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $method = lc $map->{method}; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | $method ||= 'subquery' if $map->{join} =~ /^\s*SELECT/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$method ||= "subquery"
MC/DC0%0/1
$method ||= "subquery"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $method ||= 'table' if $map->{join} =~ /^[A-Za-z0-9_]+$/i; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$method ||= "table"
MC/DC0%0/1
$method ||= "table"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | croak sprintf("Cannot join to '' without method.", $map->{join}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | unless $method eq 'subquery' || $method eq 'table'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$method eq "subquery" or $method eq "table"
MC/DC0%0/2
$method eq "subquery" or $method eq "table"
$method eq "subquery"
$method eq "table"
Truth table0%0/3
A or B
A= $method eq "subquery"B= $method eq "table"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | my $evil_sql = sprintf('SELECT * FROM %s AS "r2r_join_parent", %s AS "r2r_join_child"', | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sprintf(($method eq 'subquery' ? '(%s)' : '"%s"'), $map->{join}), | ||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | ($tmap->{sql} or $tmap->{select}) ? "($sql)" : $from, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$tmap->{"sql"} or $tmap->{"select"}
MC/DC0%0/2
$tmap->{"sql"} or $tmap->{"select"}
$tmap->{"sql"}
$tmap->{"select"}
Truth table0%0/3
A or B
A= $tmap->{"sql"}B= $tmap->{"select"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if (@{ $map->{on} }) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $evil_sql .= ' WHERE ' . | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | join ' AND ', | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | map { sprintf('"r2r_join_parent"."%s"="r2r_join_child"."%s"', $_->{parent}, $_->{child}) } | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | @{ $map->{on} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $evil_sth = $dbh->prepare($evil_sql); | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $sth->execute; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $types = $self->_get_types($sth, $dbh); | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $evil_row_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | ROW: while (my $evil_row = $evil_sth->fetchrow_hashref) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $evil_row_count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $self->handle_jmap($dbh, $callback, $table, $map, $evil_row, $types, $evil_row_count); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | delete $tmap->{-maps}; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | delete $tmap->{-jmaps}; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 5 | return $callback; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | sub handle_row | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_row: called CC=8 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 15 | my ($self, $dbh, $model, $table, $row, $types, $row_count) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | 15 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 15 | my $mappings = $self->mappings; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 15 | my $tmap = $mappings->{$table}; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # ->{graph} | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 15 | my $graph = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | $graph = $self->iri( $self->template_irisafe($tmap->{graph}, $row, $types) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 15 | ▶ | if defined $tmap->{graph}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # ->{about} | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 15 | my $subject = $self->_extract_subject_from_row($tmap, $row, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 15 | ▶ | return unless defined $subject; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # ->{typeof} | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 12 | foreach (@{ $tmap->{typeof} }) | |||||||||||||||||||||||||||||||||||||||||||||
| 307 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 12 | ▶ | $_ = $self->iri($_, $graph) unless ref $_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 12 | $callback->(statement($self->iri($subject, $graph), $rdf->type, $_)); | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 12 | foreach (@{ $tmap->{-maps} }) | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 17 | $self->handle_map($dbh, $model, $table, $row, $types, $row_count, $_, $graph, $subject); | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | sub _extract_subject_from_row | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_subject_from_row: called CC=9 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 15 | my ($self, $tmap, $row, $types) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 15 | ▶ | if ($tmap->{about} and $tmap->{_about_is_template}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$tmap->{"about"} and $tmap->{"_about_is_template"}
MC/DC50%1/2
$tmap->{"about"} and $tmap->{"_about_is_template"}
$tmap->{"about"}
$tmap->{"_about_is_template"}
Truth table66%2/3
A and B
A= $tmap->{"about"}B= $tmap->{"_about_is_template"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | return $self->template_irisafe($tmap->{about}, $row, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ▶ | elsif ($tmap->{about} and $tmap->{about} =~ m< ^ {\" ([^}]+?) \"} $ >x) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tmap->{"about"} and $tmap->{"about"} =~ / ^ {\" ([^}]+?) \"} $ /x
MC/DC0%0/2
$tmap->{"about"} and $tmap->{"about"} =~ / ^ {\" ([^}]+?) \"} $ /x
$tmap->{"about"}
$tmap->{"about"} =~ / ^ {\" ([^}]+?) \"} $ /x
Truth table33%1/3
A and B
A= $tmap->{"about"}B= $tmap->{"about"} =~ / ^ {\" ([^}]+?) \"} $ /x
| |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return $row->{$1}; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | ▶ | elsif ($tmap->{about} and $tmap->{about} =~ m< ^ { ([^}]+?) } $ >x) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$tmap->{"about"} and $tmap->{"about"} =~ / ^ { ([^}]+?) } $ /x
MC/DC0%0/2
$tmap->{"about"} and $tmap->{"about"} =~ / ^ { ([^}]+?) } $ /x
$tmap->{"about"}
$tmap->{"about"} =~ / ^ { ([^}]+?) } $ /x
Truth table33%1/3
A and B
A= $tmap->{"about"}B= $tmap->{"about"} =~ / ^ { ([^}]+?) } $ /x
| |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 12 | ▶ | return $row->{$1} if exists $row->{$1}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 12 | return $row->{lc $1}; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return ($tmap->{about} // '[]'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tmap->{"about"} // "[]"
MC/DC0%0/1
$tmap->{"about"} // "[]"
$tmap->{"about"}
Truth table0%0/2
A
A= $tmap->{"about"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | sub handle_jmap | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_jmap: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my ($self, $dbh, $model, $table, $jmap, $row, $types, $row_count) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $mappings = $self->mappings; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my $tmap = $mappings->{$table}; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # ->{graph} | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $graph = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | $graph = $self->iri( $self->template_irisafe($tmap->{graph}, $row, $types) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if defined $tmap->{graph}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # ->{about} | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $subject = $self->_extract_subject_from_row($tmap, $row, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $self->handle_map($dbh, $model, $table, $row, $types, $row_count, $jmap, $graph, $subject); | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | sub handle_map | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_map: called CC=36 SCAR=46.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 17 | my ($self, $dbh, $model, $table, $row, $types, $row_count, $map, $graph, $subject) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | 17 | state $parsers = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 17 | ▶ | $model = RDF::Trine::Model->temporary_model unless defined $model; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | my $callback = (ref $model eq 'CODE')?$model:sub{$model->add_statement(@_)}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 17 | my $mappings = $self->mappings; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 17 | my $tmap = $mappings->{$table}; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 17 | my %row = %$row; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 17 | my $column = $map->{column}; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 17 | my ($predicate, $value, $lang, $loose); | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 17 | ▶ | if ($column =~ /^"(.+)"$/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | { $column = $1; $value = $row{$column} } | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | elsif (exists $row{$column}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 12 | { $loose = 1; $value = $row{$column} } | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | elsif (exists $row{lc $column}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 5 | { $loose = 1; $value = $row{lc $column} } | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 17 | ▶ | if (my $lang_col = $map->{lang_col}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 9 | ▶ | if ($lang_col =~ /^"(.+)"$/) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | { $lang = $row{$1} } | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | elsif (defined $lang_col) | ||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 9 | ▶ | { $lang = $row{$lang_col} // $row{lc $lang_col} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$row{$lang_col} // $row{lc $lang_col}
MC/DC50%1/2
$row{$lang_col} // $row{lc $lang_col}
$row{$lang_col}
$row{lc $lang_col}
Truth table66%2/3
A // B
A= $row{$lang_col}B= $row{lc $lang_col}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 17 | ▶ | $lang //= $map->{lang}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$lang //= $map->{"lang"}
MC/DC100%2/2
$lang //= $map->{"lang"}
$lang
$map->{"lang"}
Truth table100%3/3
A //= B
A= $langB= $map->{"lang"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | my $lgraph = defined $map->{graph} | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 17 | ▶ | ? $self->iri($self->template_irisafe($map->{graph}, $row, $types)) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | : $graph; | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 17 | ▶ | if (defined $map->{parse} and uc $map->{parse} eq 'TURTLE') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $map->{"parse"} and uc $map->{"parse"} eq "TURTLE"
MC/DC0%0/2
defined $map->{"parse"} and uc $map->{"parse"} eq "TURTLE"
defined $map->{"parse"}
uc $map->{"parse"} eq "TURTLE"
Truth table33%1/3
A and B
A= defined $map->{"parse"}B= uc $map->{"parse"} eq "TURTLE"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | return unless length $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my %NS = $self->namespaces; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | my $turtle = | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | join '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | (map { sprintf("\@prefix %s: <%s>.\n", $_, $NS{$_}) } keys %NS), | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | sprintf("\@base <%s>.\n", $subject->uri), | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $value, | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | return eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $parsers->{ $map->{parse} } = RDF::Trine::Parser->new($map->{parse}); | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | $parsers->{ $map->{parse} }->parse( | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | $subject, | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | $turtle, | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | ($lgraph ? sub { $callback->($_[0], $lgraph) } : $callback), | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 17 | ▶ | if ($map->{rev} || $map->{rel}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$map->{"rev"} or $map->{"rel"}
MC/DC50%1/2
$map->{"rev"} or $map->{"rel"}
$map->{"rev"}
$map->{"rel"}
Truth table66%2/3
A or B
A= $map->{"rev"}B= $map->{"rel"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 5 | ▶ | $predicate = $map->{rev} || $map->{rel}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$map->{'rev'} || $map->{'rel'}
MC/DC0%0/2
$map->{'rev'} || $map->{'rel'}
$map->{'rev'}
$map->{'rel'}
Truth table33%1/3
A || B
A= $map->{'rev'}B= $map->{'rel'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | ▶ | if ($map->{resource}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $value = $self->template_irisafe($map->{resource}, +{ %row, '_' => $value }, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 5 | $value = $self->iri($value, $lgraph); | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | elsif ($map->{property}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | $predicate = $map->{property}; | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 12 | ▶ | if ($map->{content}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $value = $self->template($map->{content}, +{ %row, '_' => $value }, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | ▶ | if ($lang) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 8 | $value = literal($value, $lang); | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 4 | ▶ | if ($map->{datatype}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $value = literal($value, undef, $map->{datatype}); | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | elsif (!defined $map->{content}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 4 | my $type = $types->{$column}; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | ▶ | $type = $types->{lc $column} if $loose && not exists $types->{$column}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$loose and not exists $types->{$column}
MC/DC0%0/2
$loose and not exists $types->{$column}
$loose
not exists $types->{$column}
Truth table33%1/3
A and not(B)
A= $looseB= not exists $types->{$column}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 4 | $value = $self->datatyped_literal($value, $type); | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $value = literal($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 17 | ▶ | if (defined $predicate and defined $value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $predicate and defined $value
MC/DC50%1/2
defined $predicate and defined $value
defined $predicate
defined $value
Truth table66%2/3
A and B
A= defined $predicateB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 16 | ▶ | if (blessed($predicate) && $predicate->isa('RDF::RDB2RDF::R2RML::_COL_') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($predicate) and $predicate->isa("RDF::RDB2RDF::R2RML::_COL_") or not ref $predicate
builtin::blessed($predicate) and $predicate->isa("RDF::RDB2RDF::R2RML::_COL_")
MC/DC0%0/3
builtin::blessed($predicate) and $predicate->isa("RDF::RDB2RDF::R2RML::_COL_") or not ref $predicate
builtin::blessed($predicate)
$predicate->isa("RDF::RDB2RDF::R2RML::_COL_")
not ref $predicate
Truth table40%2/5
A and B or not(C)
A= builtin::blessed($predicate)B= $predicate->isa("RDF::RDB2RDF::R2RML::_COL_")C= not ref $predicate
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | or not ref $predicate) | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 16 | $predicate = $self->template_irisafe($predicate, +{ %row, '_' => $value }, $types); | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 16 | $predicate = $self->iri($predicate, $lgraph) ; | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 16 | my $lsubject = $self->iri($subject, $lgraph); | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 16 | ▶ | if ($map->{about}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $lsubject = $self->iri($self->template_irisafe($map->{about}, $row, $types), $lgraph); | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 16 | ▶ | return unless defined $lsubject; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | my $st = $map->{rev} | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 16 | ▶ | ? statement($value, $predicate, $lsubject) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | : statement($lsubject, $predicate, $value); | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 16 | ▶ | if ($lgraph) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $callback->($st, $lgraph); | |||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 16 | $callback->($st); | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | sub process_turtle | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_turtle: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my ($self, $dbh, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | unless ($options{no_json}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my $json = $self->to_json(canonical=>1, pretty=>1); | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | $json =~ s/^/# /gm; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $json = "# MAPPING\n#\n${json}\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $rv .= $json; | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $rv .= $self->SUPER::process_turtle($dbh, namespaces => {$self->namespaces}); | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $rv; | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | sub to_hashref | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hashref: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | return { | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | -namespaces => $self->_export( {$self->namespaces} ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | %{ $self->_export( $self->mappings ) }, | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 5 | *TO_JSON = \&to_hashref; | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | sub to_json | ||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_json: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my ($self, %opts) = (exists $_[1] and ref $_[1] eq 'HASH') ? ($_[0], %{ $_[1] }) : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $_[1] and ref $_[1] eq "HASH"
MC/DC0%0/2
exists $_[1] and ref $_[1] eq "HASH"
exists $_[1]
ref $_[1] eq "HASH"
Truth table0%0/3
A and B
A= exists $_[1]B= ref $_[1] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $opts{convert_blessed} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | JSON::to_json($self, {%opts}); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | sub _export | ||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_export: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my ($self, $thingy) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | return undef unless defined $thingy; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if (ref $thingy eq 'HASH' or (blessed($thingy) and $thingy->isa('RDF::Trine::NamespaceMap'))) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $thingy eq "HASH" or builtin::blessed($thingy) and $thingy->isa("RDF::Trine::NamespaceMap")
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::NamespaceMap")
MC/DC0%0/3
ref $thingy eq "HASH" or builtin::blessed($thingy) and $thingy->isa("RDF::Trine::NamespaceMap")
ref $thingy eq "HASH"
builtin::blessed($thingy)
$thingy->isa("RDF::Trine::NamespaceMap")
Truth table0%0/4
A or B and C
A= ref $thingy eq "HASH"B= builtin::blessed($thingy)C= $thingy->isa("RDF::Trine::NamespaceMap")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | while (my ($k, $v) = each %$thingy) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | $hash->{$k} = ref $v ? $self->_export($v) : $v; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | return $hash; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | if (ref $thingy eq 'ARRAY') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | return [ map { ref $_ ? $self->_export($_) : $_ } @$thingy ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | if (blessed($thingy) and $thingy->isa('RDF::RDB2RDF::R2RML::_COL_')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($thingy) and $thingy->isa("RDF::RDB2RDF::R2RML::_COL_")
MC/DC0%0/2
builtin::blessed($thingy) and $thingy->isa("RDF::RDB2RDF::R2RML::_COL_")
builtin::blessed($thingy)
$thingy->isa("RDF::RDB2RDF::R2RML::_COL_")
Truth table0%0/3
A and B
A= builtin::blessed($thingy)B= $thingy->isa("RDF::RDB2RDF::R2RML::_COL_")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | return "$thingy"; | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if (blessed($thingy) and $thingy->isa('RDF::Trine::Node::Resource')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::Resource")
MC/DC0%0/2
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::Resource")
builtin::blessed($thingy)
$thingy->isa("RDF::Trine::Node::Resource")
Truth table0%0/3
A and B
A= builtin::blessed($thingy)B= $thingy->isa("RDF::Trine::Node::Resource")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | return $self->_mktemplate($thingy->uri); | |||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | ▶ | if (blessed($thingy) and $thingy->isa('RDF::Trine::Node::BlankNode')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::BlankNode")
MC/DC0%0/2
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::BlankNode")
builtin::blessed($thingy)
$thingy->isa("RDF::Trine::Node::BlankNode")
Truth table0%0/3
A and B
A= builtin::blessed($thingy)B= $thingy->isa("RDF::Trine::Node::BlankNode")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 554 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return '_:'.$self->_mktemplate($thingy->identifier); | |||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | if (blessed($thingy) and $thingy->isa('RDF::Trine::Node::Literal')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::Literal")
MC/DC0%0/2
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Node::Literal")
builtin::blessed($thingy)
$thingy->isa("RDF::Trine::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($thingy)B= $thingy->isa("RDF::Trine::Node::Literal")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 559 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | warn "This shouldn't happen!"; | |||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | return $self->_mktemplate($thingy->literal_value); | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if (blessed($thingy) and $thingy->isa('RDF::Trine::Namespace')) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Namespace")
MC/DC0%0/2
builtin::blessed($thingy) and $thingy->isa("RDF::Trine::Namespace")
builtin::blessed($thingy)
$thingy->isa("RDF::Trine::Namespace")
Truth table0%0/3
A and B
A= builtin::blessed($thingy)B= $thingy->isa("RDF::Trine::Namespace")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | return $self->_mktemplate($thingy->uri->uri); | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | warn "This shouldn't happen either!" if ref $thingy; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | return "$thingy"; | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||