| 1 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | package DAIA::Object; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | #ABSTRACT: Abstract base class of all DAIA classes | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 12 | our $VERSION = '0.43'; #VERSION | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Carp::Clan; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Data::Validate::URI qw(is_uri is_web_uri); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use Scalar::Util qw(refaddr reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 12 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | our @HIDDEN_PROPERTIES = | |||||||||||||||||||||||||||||||||||||||||
| 15 | qw(to format xmlns cgi header xmlheader xslt pi callback exitif noutf8); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 211 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 211 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 211 | my $self = bless { }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 211 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 211 | ▶ | if ( @_ == 1 and ref($_[0]) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 42 | %hash = %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | ▶ | } elsif ( @_ == 1 and ref($_[0]) eq $class ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@_ == 1 and ref $_[0] eq $class
MC/DC100%2/2
@_ == 1 and ref $_[0] eq $class
@_ == 1
ref $_[0] eq $class
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq $class
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 10 | %hash = %{$_[0]->struct}; # copy constructor | |||||||||||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 159 | %hash = $self->_buildargs(@_); | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # abstract class handling | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 211 | ▶ | if ( $class eq 'DAIA::Availability' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | ▶ | croak "Availability status missing" unless exists $hash{status}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | $self->status( $hash{status} ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | delete $hash{status}; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 209 | my %hidden; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 209 | foreach ( @HIDDEN_PROPERTIES ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | 2299 | ▶ | next unless exists $hash{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | $hidden{$_} = $hash{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | delete $hash{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 209 | ▶ | $self->{_hidden} = \%hidden if %hidden; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | ▶ | no strict 'refs'; ##no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 209 | my $PROPERTIES = \%{$class."::PROPERTIES"}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 209 | foreach my $property (keys %{$PROPERTIES}) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 915 | ▶ | $self->$property( undef ) unless exists $hash{$property}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 208 | foreach my $property (keys %hash) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 305 | $self->$property( $hash{$property} ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | #use Data::Dumper; print Dumper($self)."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 206 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 18 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | #print "APPEND: " . ref($self) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 18 | foreach my $value (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 68 | 17 | ▶ | next unless defined $value; # ignore undefined values | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | #print "- " . ref($value) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 16 | ▶ | croak "Cannot add $value to " . ref($self) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | unless ref($value) =~ /^DAIA::([A-Z][a-z]+)$/; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 16 | my $property = lc($1); | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | #no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | #my $PROPERTIES = \%{$class."::PROPERTIES"}; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # repeatable | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | ▶ | if ( ref($self->{$property}) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 11 | push @{$self->{$property}}, $value; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | $self->$property( $value ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | ▶ | sub xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | my ($self, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 12 | $self->_hidden_prop( \%param ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 12 | ▶ | my $xmlns = $param{xmlns} || ($param{xslt} or $param{header}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$param{'xmlns'} || ($param{'xslt'} || $param{'header'})
$param{"xslt"} or $param{"header"}
MC/DC66%2/3
$param{'xmlns'} || ($param{'xslt'} || $param{'header'})
$param{'xmlns'}
$param{"xslt"}
$param{"header"}
Truth table75%3/4
A || B or C
A= $param{'xmlns'}B= $param{"xslt"}C= $param{"header"}
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | ▶ | my $pi = $param{pi} || [ ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$param{'pi'} || []
MC/DC0%0/1
$param{'pi'} || []
$param{'pi'}
Truth table50%1/2
A
A= $param{'pi'}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | ▶ | $pi = [$pi] unless (reftype($pi) || '') eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
builtin::reftype($pi) || ''
MC/DC0%0/1
builtin::reftype($pi) || ''
builtin::reftype($pi)
Truth table50%1/2
A
A= builtin::reftype($pi)
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | push @$pi, 'xml-stylesheet type="text/xsl" href="' . xml_escape_value($param{xslt}) . '"' | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | ▶ | if $param{xslt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | @$pi = map { $_ =~ /^<\?.*\?>$/ ? "$_\n" : "<?$_?>\n" } @$pi; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | my $name = lc(ref($self)); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | $name =~ s/^daia:://; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | ▶ | $name = 'daia' if $name eq 'response'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | my $struct = $self->struct; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | ▶ | $struct->{xmlns} = "http://ws.gbv.de/daia/" if $xmlns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | my $xml = xml_write( $name, $struct, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | ▶ | delete $struct->{xmlns} if $xmlns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | $xml = join('', @$pi ) . $xml; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | ▶ | $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n$xml" if $param{header}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 134 | ▶ | sub struct { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
struct: called CC=10 SCAR=23.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 134 | my ($self, $json) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 134 | my $struct = { }; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 134 | foreach my $property (keys %$self) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 263 | ▶ | next unless $property =~ /^[a-z]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 260 | ▶ | if (ref $self->{$property} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 21 | $struct->{$property} = [ map { $_->struct($json) } @{$self->{$property}} ]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } elsif ( UNIVERSAL::isa( $self->{$property}, "DAIA::Object" ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 12 | $struct->{$property} = $self->{$property}->struct; | |||||||||||||||||||||||||||||||||||||||||
| 126 | ▶ | } elsif ( UNIVERSAL::isa( $self->{$property}, 'JSON::Boolean' ) and not $json ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
UNIVERSAL::isa($self->{$property}, "JSON::Boolean") and not $json
MC/DC0%0/2
UNIVERSAL::isa($self->{$property}, "JSON::Boolean") and not $json
UNIVERSAL::isa($self->{$property}, "JSON::Boolean")
not $json
Truth table33%1/3
A and not(B)
A= UNIVERSAL::isa($self->{$property}, "JSON::Boolean")B= not $json
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $struct->{$property} = $self->{$property} ? 'true' : 'false'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | ▶ | } elsif( $property eq 'label' and $self->{$property} eq '' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$property eq "label" and $self->{$property} eq ""
MC/DC100%2/2
$property eq "label" and $self->{$property} eq ""
$property eq "label"
$self->{$property} eq ""
Truth table100%3/3
A and B
A= $property eq "label"B= $self->{$property} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | # ignore empty string label | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # remove characters not allowed in XML 1.0 | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 212 | my $value = $self->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 212 | $value =~ s/[^\x09\x0A\x0D\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//go; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 212 | $struct->{$property} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 134 | return $struct; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 11 | ▶ | sub json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | my ($self, $callback) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | $callback = $self->{_hidden}->{callback} | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 11 | ▶ | if @_ < 2 and $self->{_hidden} and exists $self->{_hidden}->{callback}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@_ < 2 and $self->{"_hidden"} and exists $self->{"_hidden"}{"callback"}
@_ < 2 and $self->{"_hidden"}
MC/DC66%2/3
@_ < 2 and $self->{"_hidden"} and exists $self->{"_hidden"}{"callback"}
@_ < 2
$self->{"_hidden"}
exists $self->{"_hidden"}{"callback"}
Truth table75%3/4
A and B and C
A= @_ < 2B= $self->{"_hidden"}C= exists $self->{"_hidden"}{"callback"}
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 11 | my $json = JSON->new->pretty->encode( $self->struct(1) ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 11 | ▶ | if ( defined $callback and $callback =~ /^[a-z][a-z0-9._\[\]]*$/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $callback and $callback =~ /^[a-z][a-z0-9._\[\]]*$/i
MC/DC50%1/2
defined $callback and $callback =~ /^[a-z][a-z0-9._\[\]]*$/i
defined $callback
$callback =~ /^[a-z][a-z0-9._\[\]]*$/i
Truth table66%2/3
A and B
A= defined $callbackB= $callback =~ /^[a-z][a-z0-9._\[\]]*$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | return "$callback($json);" | |||||||||||||||||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | return $json; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub rdfhash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rdfhash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return { }; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my ($self, $format) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return unless $format and grep { $_ eq $format } DAIA->formats; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format and grep {$_ eq $format;} "DAIA"->formats
MC/DC0%0/2
$format and grep {$_ eq $format;} "DAIA"->formats
$format
grep {$_ eq $format;} "DAIA"->formats
Truth table0%0/3
A and B
A= $formatB= grep {$_ eq $format;} "DAIA"->formats
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $content = ''; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ($format eq 'xml') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $content = $self->xml(xmnls => 1); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } elsif ($format eq 'json') { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $content = $self->json; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } elsif ($format eq 'rdfjson') { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $content = JSON->new->pretty->encode($self->rdfhash()); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } elsif ( $DAIA::TRINE_SERIALIZER ) { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 173 | # NOTE: RDF/XML dumps all namespaces, so avoid it | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $opt{namespaces} = $DAIA::RDF_NS if $DAIA::RDF_NS and $format ne 'rdfxml'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$DAIA::RDF_NS and $format ne "rdfxml"
MC/DC0%0/2
$DAIA::RDF_NS and $format ne "rdfxml"
$DAIA::RDF_NS
$format ne "rdfxml"
Truth table0%0/3
A and B
A= $DAIA::RDF_NSB= $format ne "rdfxml"
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $ser; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ( $DAIA::GRAPHVIZ and $DAIA::TRINE_MODEL and $format =~ /^(dot|svg)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$DAIA::GRAPHVIZ and $DAIA::TRINE_MODEL and $format =~ /^(dot|svg)$/
$DAIA::GRAPHVIZ and $DAIA::TRINE_MODEL
MC/DC0%0/3
$DAIA::GRAPHVIZ and $DAIA::TRINE_MODEL and $format =~ /^(dot|svg)$/
$DAIA::GRAPHVIZ
$DAIA::TRINE_MODEL
$format =~ /^(dot|svg)$/
Truth table0%0/4
A and B and C
A= $DAIA::GRAPHVIZB= $DAIA::TRINE_MODELC= $format =~ /^(dot|svg)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $ser = $DAIA::GRAPHVIZ->new( as => $format, %opt ); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $ser = eval { $DAIA::TRINE_SERIALIZER->new( $format, %opt ); }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ($ser) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | # NOTE: We could get rid of RDF::Trine::Model if hashref converted directly to iterator | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $model = $DAIA::TRINE_MODEL->temporary_model; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $model->add_hashref( $self->rdfhash ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $content = $ser->serialize_model_to_string( $model ); | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | ▶ | sub rdfuri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rdfuri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | ▶ | return $self->{id} if $self->{id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | my $id = lc(ref($self)).refaddr($self); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $id =~ s/.*::/_:/; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | return $id; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub rdftype { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rdftype: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 1443 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=38 SCAR=38.3
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1443 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 1443 | ▶ | my $class = ref($self) or croak "$self is not an object"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 1443 | my $method = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 1443 | $method =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 1443 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 1232 | my $property = $method; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 1232 | ▶ | $property = lc($2) if $property =~ /^(add|provide)([A-Z][a-z]+)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 12 | ▶ | no strict 'refs'; ##no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1232 | my $PROPERTIES = \%{$class."::PROPERTIES"}; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | croak "Method $class->$method ($property) does not exist" | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 1232 | ▶ | unless exists $PROPERTIES->{$property}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1231 | my $opt = $PROPERTIES->{$property}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # TODO: conflicting properties? | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 1231 | ▶ | if ( $method =~ /^add/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | croak "$class->$property is not repeatable or has no type" | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 9 | ▶ | unless $opt->{repeatable} and $opt->{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"repeatable"} and $opt->{"type"}
MC/DC0%0/2
$opt->{"repeatable"} and $opt->{"type"}
$opt->{"repeatable"}
$opt->{"type"}
Truth table33%1/3
A and B
A= $opt->{"repeatable"}B= $opt->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | my $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 9 | ▶ | if ( not UNIVERSAL::isa( $_[0], $opt->{type} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | $value = eval $opt->{type}."->new( \@_ )"; ##no critic | |||||||||||||||||||||||||||||||||||||||||
| 232 | 8 | ▶ | croak $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 9 | return $self->add( $value ); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } elsif( $method =~ /^provide/ ) { # set only if not set | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ( defined $self->{$property} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | # getter | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | return $opt->{repeatable} ? @{$self->{$property} || []} : $self->{$property} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{$property} || []
MC/DC0%0/1
$self->{$property} || []
$self->{$property}
Truth table0%0/2
A
A= $self->{$property}
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return eval "\$self->$property(\@_)"; ##no critic | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # called as getter | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 1222 | ▶ | return $opt->{repeatable} ? @{$self->{$property} || []} : $self->{$property} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$self->{$property} || []
MC/DC100%1/1
$self->{$property} || []
$self->{$property}
Truth table100%2/2
A
A= $self->{$property}
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | if ( @_ == 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 1064 | my $value = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # called as clearer (may imply setting the default value) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 1064 | ▶ | if (not defined $value or (ref($value) eq 'ARRAY' and @{$value} == 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not defined $value or ref $value eq "ARRAY" and @{$value;} == 0
ref $value eq "ARRAY" and @{$value;} == 0
MC/DC100%3/3
not defined $value or ref $value eq "ARRAY" and @{$value;} == 0
not defined $value
ref $value eq "ARRAY"
@{$value;} == 0
Truth table100%4/4
not(A) or B and C
A= not defined $valueB= ref $value eq "ARRAY"C= @{$value;} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 670 | ▶ | if ( exists $opt->{default} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | $value = ref($opt->{default}) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 162 | ▶ | ? $opt->{default}() : $opt->{default}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 669 | ▶ | if ( defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 97 | $self->{$property} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 572 | ▶ | delete $self->{$property} if exists $self->{$property}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 669 | return; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 394 | ▶ | if ( $opt->{type} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | # set one or more typed values | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | # arguments must be either an array ref or a list of types or a simple list | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 85 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 85 | ▶ | if ( ref($_[0]) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 22 | ▶ | croak "too many arguments" if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 22 | @args = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } elsif ( UNIVERSAL::isa( $_[0], $opt->{type} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # treat ( $obj, ... ) as ( [ $obj, ... ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 31 | @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 32 | @args = ( [ @_ ] ); # one element | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | croak "$class->$property is not repeatable" | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 85 | ▶ | if ( @args > 1 and not $opt->{repeatable}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args > 1 and not $opt->{"repeatable"}
MC/DC0%0/2
@args > 1 and not $opt->{"repeatable"}
@args > 1
not $opt->{"repeatable"}
Truth table66%2/3
A and not(B)
A= @args > 1B= not $opt->{"repeatable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | my @values = map { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 85 | my $v; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 97 | ▶ | if ( ref($_) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 32 | $v = eval $opt->{type}.'->new( @{$_} )'; ##no critic | |||||||||||||||||||||||||||||||||||||||||
| 287 | 32 | ▶ | croak $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | } elsif ( UNIVERSAL::isa( $_, $opt->{type} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 56 | $v = $_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 9 | $v = eval $opt->{type}.'->new( $_ )'; ##no critic | |||||||||||||||||||||||||||||||||||||||||
| 292 | 9 | ▶ | croak $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 97 | $v; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } @args; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 85 | ▶ | $self->{$property} = $opt->{repeatable} ? \@values : $values[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # set an untyped value (never repeatable, stringified unless filtered) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 309 | ▶ | if( $opt->{fixed} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $value = $opt->{fixed}; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } elsif( $opt->{filter} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 309 | $value = $opt->{filter}( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 309 | ▶ | croak "$class->$property did not pass value constraint: " . join(',',@_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $value = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 297 | $self->{$property} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 382 | $self; # if called as setter, return the object for chaining | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 25 | ▶ | sub xml_write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml_write: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 25 | my ($name, $struct, $level) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 25 | my $indent = (' ' x $level); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 25 | my $tag = "$indent<$name"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 25 | my $content = ''; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 25 | ▶ | if (defined $struct->{content}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 13 | $content = $struct->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 13 | delete $struct->{content}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 25 | ▶ | my @attr = grep { ! ref($struct->{$_}) and $_ ne 'label' } keys %$struct; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
!ref($struct->{$_}) && $_ ne 'label'
MC/DC100%2/2
!ref($struct->{$_}) && $_ ne 'label'
!ref($struct->{$_})
$_ ne 'label'
Truth table100%3/3
not(A) && B
A= !ref($struct->{$_})B= $_ ne 'label'
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 25 | @attr = map { "$_=\"".xml_escape_value($struct->{$_}).'"' } @attr; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 25 | ▶ | $tag .= " " . join(" ", @attr) if @attr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | # get the right order | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 25 | my @order = qw(message institution document label department storage available unavailable); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 25 | my @children = grep { defined $struct->{$_} } @order; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 25 | my %has = map { $_ => 1 } @children; | |||||||||||||||||||||||||||||||||||||||||
| 338 | # append additional children | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 25 | ▶ | push @children, grep { ref($struct->{$_}) and not $has{$_} } keys %$struct; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $struct->{$_} && !$has{$_}
MC/DC100%2/2
ref $struct->{$_} && !$has{$_}
ref $struct->{$_}
!$has{$_}
Truth table100%3/3
A && not(B)
A= ref $struct->{$_}B= !$has{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 25 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 25 | ▶ | if (@children) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | push @lines, "$tag>"; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | foreach my $k (@children) { | |||||||||||||||||||||||||||||||||||||||||
| 345 | 15 | $k =~ s/^\d//; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 15 | ▶ | if ( $k eq 'label' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | push @lines, "$indent <label>".xml_escape_value($struct->{label})."</label>"; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } elsif ( ref($struct->{$k}) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | push @lines, xml_write($k, $struct->{$k}, $level+1); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } elsif ( ref($struct->{$k}) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | foreach my $v (@{$struct->{$k}}) { | |||||||||||||||||||||||||||||||||||||||||
| 352 | 10 | push @lines, xml_write($k, $v, $level+1); | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 6 | push @lines, "$indent</$name>"; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 19 | ▶ | if ( $content ne '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 13 | push @lines, "$tag>" . xml_escape_value($content) . "</$name>"; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 6 | push @lines, "$tag />"; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 25 | return join("\n", @lines); | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 38 | ▶ | sub xml_escape_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml_escape_value: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 38 | my($data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 38 | ▶ | return '' unless defined($data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 38 | $data =~ s/&/&/sg; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 38 | $data =~ s/</</sg; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 38 | $data =~ s/>/>/sg; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 38 | $data =~ s/"/"/sg; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 38 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 31 | ▶ | sub _buildargs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_buildargs: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 31 | shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 31 | ▶ | croak "uneven parameter list" if (@_ % 2); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 31 | @_; | |||||||||||||||||||||||||||||||||||||||||
| 384 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 12 | ▶ | sub _hidden_prop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hidden_prop: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 12 | ▶ | return unless $self->{_hidden}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | my $hashref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | foreach ( @HIDDEN_PROPERTIES ) { | |||||||||||||||||||||||||||||||||||||||||
| 393 | 11 | ▶ | next if exists $hashref->{$_} or not exists $self->{_hidden}->{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $hashref->{$_} or not exists $self->{"_hidden"}{$_}
MC/DC50%1/2
exists $hashref->{$_} or not exists $self->{"_hidden"}{$_}
exists $hashref->{$_}
not exists $self->{"_hidden"}{$_}
Truth table66%2/3
A or not(B)
A= exists $hashref->{$_}B= not exists $self->{"_hidden"}{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | $hashref->{$_} = $self->{_hidden}->{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub _enable_utf8_layer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enable_utf8_layer: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | return unless eval{ can($fh, 'binmode'); }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | foreach my $layer ( PerlIO::get_layers( $fh ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | return if $layer =~ /^encoding|^utf8/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | binmode $fh, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | our %COMMON_PROPERTIES =( | ||||||||||||||||||||||||||||||||||||||||||
| 409 | id => { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 14 | ▶ | filter => sub { my $v = "$_[0]"; $v =~ s/^\s+|\s$//g; is_uri($v) ? $v : undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 412 | href => { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 17 | ▶ | filter => sub { my $v = "$_[0]"; is_web_uri($v) ? $v : undef; }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 12 | predicate => 'http://xmlns.com/foaf/0.1/page', | |||||||||||||||||||||||||||||||||||||||||
| 415 | rdftype => 'resource' | ||||||||||||||||||||||||||||||||||||||||||
| 416 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | message => { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | type => 'DAIA::Message', | ||||||||||||||||||||||||||||||||||||||||||
| 419 | repeatable => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 420 | predicate => 'http://purl.org/dc/terms/description', | ||||||||||||||||||||||||||||||||||||||||||
| 421 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 422 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | __END__ | ||||||||||||||||||||||||||||||||||||||||||