| 1 | # RDF::Trine::Node::Literal | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | RDF::Trine::Node::Literal - RDF Node class for literals | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | This document describes RDF::Trine::Node::Literal version 1.019 | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | package RDF::Trine::Node::Literal; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 68 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 68 | ▶ | use base qw(RDF::Trine::Node); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 68 | ▶ | use RDF::Trine::Error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 68 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 68 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 68 | ▶ | use Carp qw(carp croak confess); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 68 | our ($VERSION, $USE_XMLLITERALS, $USE_FORMULAE); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 68 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 68 | $VERSION = '1.019'; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | eval "use RDF::Trine::Node::Literal::XML;"; ## no critic (ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 68 | ▶ | $USE_XMLLITERALS = (RDF::Trine::Node::Literal::XML->can('new')) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | eval "use RDF::Trine::Node::Formula;"; ## no critic (ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 68 | ▶ | $USE_FORMULAE = (RDF::Trine::Node::Formula->can('new')) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1314 | ▶ | use overload '""' => sub { $_[0]->sse }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 68 | ; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | L<RDF::Trine::Node> class. | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =item C<new ( $string, $lang, $datatype, $canonical_flag )> | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Returns a new Literal structure. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2360 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2360 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2360 | my $literal = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2360 | my $lang = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2360 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2360 | my $canon = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2360 | ▶ | unless (defined($literal)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | throw RDF::Trine::Error::MethodInvocationError -text => "Literal constructor called with an undefined value"; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2360 | ▶ | if (blessed($dt) and $dt->isa('RDF::Trine::Node::Resource')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($dt) and $dt->isa("RDF::Trine::Node::Resource")
MC/DC50%1/2
builtin::blessed($dt) and $dt->isa("RDF::Trine::Node::Resource")
builtin::blessed($dt)
$dt->isa("RDF::Trine::Node::Resource")
Truth table66%2/3
A and B
A= builtin::blessed($dt)B= $dt->isa("RDF::Trine::Node::Resource")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 167 | $dt = $dt->uri_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2360 | ▶ | if ($dt and $canon) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dt and $canon
MC/DC100%2/2
$dt and $canon
$dt
$canon
Truth table100%3/3
A and B
A= $dtB= $canon
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 25 | $literal = $class->canonicalize_literal_value( $literal, $dt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2360 | ▶ | if ($USE_XMLLITERALS and defined($dt) and $dt eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$RDF::Trine::Node::Literal::USE_XMLLITERALS and defined $dt and $dt eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
$RDF::Trine::Node::Literal::USE_XMLLITERALS and defined $dt
MC/DC0%0/3
$RDF::Trine::Node::Literal::USE_XMLLITERALS and defined $dt and $dt eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
$RDF::Trine::Node::Literal::USE_XMLLITERALS
defined $dt
$dt eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
Truth table25%1/4
A and B and C
A= $RDF::Trine::Node::Literal::USE_XMLLITERALSB= defined $dtC= $dt eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return RDF::Trine::Node::Literal::XML->new( $literal, $lang, $dt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | } elsif ($USE_FORMULAE and defined($dt) and $dt eq RDF::Trine::Node::Formula->literal_datatype) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$RDF::Trine::Node::Literal::USE_FORMULAE and defined $dt and $dt eq "RDF::Trine::Node::Formula"->literal_datatype
$RDF::Trine::Node::Literal::USE_FORMULAE and defined $dt
MC/DC0%0/3
$RDF::Trine::Node::Literal::USE_FORMULAE and defined $dt and $dt eq "RDF::Trine::Node::Formula"->literal_datatype
$RDF::Trine::Node::Literal::USE_FORMULAE
defined $dt
$dt eq "RDF::Trine::Node::Formula"->literal_datatype
Truth table25%1/4
A and B and C
A= $RDF::Trine::Node::Literal::USE_FORMULAEB= defined $dtC= $dt eq "RDF::Trine::Node::Formula"->literal_datatype
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return RDF::Trine::Node::Formula->new( $literal ); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2360 | return $class->_new( $literal, $lang, $dt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2360 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2360 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2360 | my $literal = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2360 | my $lang = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2360 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2360 | my $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2360 | ▶ | if ($lang and $dt) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$lang and $dt
MC/DC100%2/2
$lang and $dt
$lang
$dt
Truth table100%3/3
A and B
A= $langB= $dt
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | throw RDF::Trine::Error::MethodInvocationError ( -text => "Literal values cannot have both language and datatype" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2359 | ▶ | if ($lang) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 89 | my $oldlang = $lang; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | # http://tools.ietf.org/html/bcp47#section-2.1.1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # All subtags use lowercase letters | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 89 | $lang = lc($lang); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # with 2 exceptions: subtags that neither appear at the start of the tag nor occur after singletons | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # i.e. there's a subtag of length at least 2 preceding the exception; and a following subtag or end-of-tag | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # 1. two-letter subtags are all uppercase | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 89 | $lang =~ s{(?<=\w\w-)(\w\w)(?=($|-))}{\U$1}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # 2. four-letter subtags are titlecase | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 89 | $lang =~ s{(?<=\w\w-)(\w\w\w\w)(?=($|-))}{\u\L$1}g; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 89 | $self = [ $literal, $lang, undef ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } elsif ($dt) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 372 | ▶ | if (blessed($dt)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $dt = $dt->uri_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 372 | $self = [ $literal, undef, $dt ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1898 | $self = [ $literal ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2359 | return bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =item C<< literal_value >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Returns the string value of the literal. | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 8270 | ▶ | sub literal_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
literal_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8270 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8270 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | $self->[0] = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8270 | return $self->[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =item C<< literal_value_language >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | Returns the language tag of the ltieral. | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 7973 | ▶ | sub literal_value_language { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
literal_value_language: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7973 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7973 | return $self->[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | =item C<< literal_datatype >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Returns the datatype of the literal. | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7464 | ▶ | sub literal_datatype { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
literal_datatype: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 7464 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7464 | return $self->[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =item C<< value >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | Returns the literal value. | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 590 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 590 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 590 | return $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | =item C<< sse >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Returns the SSE string for this literal. | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3458 | ▶ | sub sse { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3458 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 3458 | my $literal = $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3458 | my $escaped = $self->_unicode_escape( $literal ); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 3458 | $literal = $escaped; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 3458 | ▶ | if (defined(my $lang = $self->literal_value_language)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 162 | return qq("${literal}"\@${lang}); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } elsif (defined(my $dt = $self->literal_datatype)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 803 | return qq("${literal}"^^<${dt}>); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2493 | return qq("${literal}"); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =item C<< as_string >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | Returns a string representation of the node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 2613 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2613 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2613 | my $string = '"' . $self->literal_value . '"'; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2613 | ▶ | if (defined(my $dt = $self->literal_datatype)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 587 | $string .= '^^<' . $dt . '>'; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | } elsif (defined(my $lang = $self->literal_value_language)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 159 | $string .= '@' . $lang; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2613 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | =item C<< as_ntriples >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | Returns the node in a string form suitable for NTriples serialization. | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 649 | ▶ | sub as_ntriples { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_ntriples: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 649 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 649 | my $literal = $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 649 | my $escaped = $self->_unicode_escape( $literal ); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | 649 | $literal = $escaped; | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 649 | ▶ | if (defined(my $lang = $self->literal_value_language)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 22 | return qq("${literal}"\@${lang}); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } elsif (defined(my $dt = $self->literal_datatype)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 162 | return qq("${literal}"^^<${dt}>); | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 465 | return qq("${literal}"); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | =item C<< type >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | Returns the type string of this node. | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 621 | ▶ | sub type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 621 | return 'LITERAL'; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | =item C<< has_language >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | Returns true if this literal is language-tagged, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 568 | ▶ | sub has_language { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_language: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 568 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 568 | ▶ | return defined($self->literal_value_language) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | =item C<< has_datatype >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | Returns true if this literal is datatyped, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 108 | ▶ | sub has_datatype { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_datatype: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 108 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 108 | ▶ | return defined($self->literal_datatype) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | =item C<< equal ( $node ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | Returns true if the two nodes are equal, false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 17 | ▶ | sub equal { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 17 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 17 | ▶ | return 0 unless (blessed($node) and $node->isa('RDF::Trine::Node::Literal')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Literal")
MC/DC100%2/2
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Literal")
builtin::blessed($node)
$node->isa("RDF::Trine::Node::Literal")
Truth table100%3/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Trine::Node::Literal")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 11 | ▶ | return 0 unless ($self->literal_value eq $node->literal_value); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 10 | ▶ | if ($self->literal_datatype or $node->literal_datatype) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->literal_datatype or $node->literal_datatype
MC/DC50%1/2
$self->literal_datatype or $node->literal_datatype
$self->literal_datatype
$node->literal_datatype
Truth table66%2/3
A or B
A= $self->literal_datatypeB= $node->literal_datatype
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | ▶ | return 0 unless ($self->literal_datatype eq $node->literal_datatype); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 9 | ▶ | if ($self->literal_value_language or $node->literal_value_language) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->literal_value_language or $node->literal_value_language
MC/DC50%1/2
$self->literal_value_language or $node->literal_value_language
$self->literal_value_language
$node->literal_value_language
Truth table66%2/3
A or B
A= $self->literal_value_languageB= $node->literal_value_language
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | return 0 unless ($self->literal_value_language eq $node->literal_value_language); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # called to compare two nodes of the same type | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 144 | ▶ | sub _compare { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compare: called CC=8 SCAR=37.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 144 | my $a = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 144 | my $b = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 144 | ▶ | if ($a->literal_value ne $b->literal_value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 144 | return ($a->literal_value cmp $b->literal_value); | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # the nodes have the same lexical value | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ($a->has_language and $b->has_language) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a->has_language and $b->has_language
MC/DC0%0/2
$a->has_language and $b->has_language
$a->has_language
$b->has_language
Truth table0%0/3
A and B
A= $a->has_languageB= $b->has_language
| |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return ($a->literal_value_language cmp $b->literal_value_language); | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($a->has_datatype and $b->has_datatype) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$a->has_datatype and $b->has_datatype
MC/DC0%0/2
$a->has_datatype and $b->has_datatype
$a->has_datatype
$b->has_datatype
Truth table0%0/3
A and B
A= $a->has_datatypeB= $b->has_datatype
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return ($a->literal_datatype cmp $b->literal_datatype); | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } elsif ($a->has_datatype) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | } elsif ($b->has_datatype) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | =item C<< canonicalize >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | Returns a new literal node object whose value is in canonical form (where applicable). | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 588 | ▶ | sub canonicalize { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 588 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 588 | my $class = ref($self); | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | 588 | my $dt = $self->literal_datatype; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 588 | my $lang = $self->literal_value_language; | |||||||||||||||||||||||||||||||||||||||||||||
| 316 | 588 | my $value = $self->value; | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 588 | ▶ | if (defined $dt) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 5 | $value = RDF::Trine::Node::Literal->canonicalize_literal_value( $value, $dt, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 588 | return $class->new($value, $lang, $dt); | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | =item C<< canonicalize_literal_value ( $string, $datatype, $warn ) >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | If C<< $datatype >> is a recognized datatype, returns the canonical lexical | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | representation of the value C<< $string >>. Otherwise returns C<< $string >>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | Currently, xsd:integer, xsd:decimal, and xsd:boolean are canonicalized. | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | Additionally, invalid lexical forms for xsd:float, xsd:double, and xsd:dateTime | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | will trigger a warning. | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 40 | ▶ | sub canonicalize_literal_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize_literal_value: called CC=36 SCAR=43.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 40 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 40 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 40 | my $warn = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 40 | ▶ | if ($dt eq 'http://www.w3.org/2001/XMLSchema#integer') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 9 | ▶ | if ($value =~ m/^([-+])?(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 9 | ▶ | my $sign = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 9 | my $num = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 9 | ▶ | $sign = '' if ($sign eq '+'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 9 | $num =~ s/^0+(\d)/$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 9 | return "${sign}${num}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | warn "Bad lexical form for xsd:integer: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#decimal') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | ▶ | if ($value =~ m/^([-+])?((\d+)([.]\d*)?)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | ▶ | my $sign = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 5 | my $num = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5 | my $int = $3; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 5 | my $frac = $4; | |||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | $sign = '' if ($sign eq '+'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | $num =~ s/^0+(.)/$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | $num =~ s/[.](\d)0+$/.$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | ▶ | if ($num =~ /^[.]/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | $num = "0$num"; | |||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | ▶ | if ($num !~ /[.]/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $num = "${num}.0"; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 5 | return "${sign}${num}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | } elsif ($value =~ m/^([-+])?([.]\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | my $sign = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$1 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | my $num = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $sign = '' if ($sign eq '+'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $num =~ s/^0+(.)/$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return "${sign}${num}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | warn "Bad lexical form for xsd:deciaml: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $value = sprintf('%f', $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#float') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | ▶ | if ($value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | my $sign = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 8 | my $inf = $4; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | 8 | my $nan = $5; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | ▶ | $sign = '' if ($sign eq '+'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | ▶ | return "${sign}$inf" if ($inf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 6 | ▶ | return $nan if ($nan); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | $value = sprintf('%E', $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 5 | $value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | 5 | $sign = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 5 | $inf = $4; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | 5 | $nan = $5; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | 5 | my $num = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | 5 | my $exp = $3; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | 5 | $num =~ s/[.](\d+?)0+/.$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | 5 | $exp =~ tr/e/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 395 | 5 | $exp =~ s/E[+]/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | 5 | $exp =~ s/E(-?)0+([1-9])$/E$1$2/; | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | $exp =~ s/E(-?)0+$/E${1}0/; | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | 5 | return "${sign}${num}${exp}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | warn "Bad lexical form for xsd:float: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $value = sprintf('%E', $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $value =~ s/E[+]/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $value =~ s/E0+(\d)/E$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $value =~ s/(\d)0+E/$1E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#double') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 8 | ▶ | if ($value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 8 | my $sign = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | 8 | my $inf = $4; | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | 8 | my $nan = $5; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 8 | ▶ | $sign = '' if ($sign eq '+'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 8 | ▶ | return "${sign}$inf" if ($inf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | ▶ | return $nan if ($nan); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 5 | $value = sprintf('%E', $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 5 | $value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/; | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 5 | $sign = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 5 | $inf = $4; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 5 | $nan = $5; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | 5 | my $num = $2; | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | my $exp = $3; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 5 | $num =~ s/[.](\d+?)0+/.$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 5 | $exp =~ tr/e/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 5 | $exp =~ s/E[+]/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | 5 | $exp =~ s/E(-?)0+([1-9])$/E$1$2/; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | 5 | $exp =~ s/E(-?)0+$/E${1}0/; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | 5 | return "${sign}${num}${exp}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | warn "Bad lexical form for xsd:double: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $value = sprintf('%E', $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $value =~ s/E[+]/E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $value =~ s/E0+(\d)/E$1/; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $value =~ s/(\d)0+E/$1E/; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 10 | ▶ | if ($value =~ m/^(true|false|0|1)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 10 | ▶ | $value = 'true' if ($value eq '1'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 10 | ▶ | $value = 'false' if ($value eq '0'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 10 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | warn "Bad lexical form for xsd:boolean: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#dateTime') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($value =~ m/^-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # XXX need to canonicalize the dateTime | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | warn "Bad lexical form for xsd:boolean: '$value'" if ($warn); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | =item C<< is_canonical_lexical_form >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 24 | ▶ | sub is_canonical_lexical_form { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_canonical_lexical_form: called CC=17 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | 24 | my $value = $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | 24 | my $dt = $self->literal_datatype; | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 24 | ▶ | unless ($dt =~ qr<^http://www.w3.org/2001/XMLSchema#(integer|decimal|float|double|boolean|dateTime|non(Positive|Negative)Integer|(positive|negative)Integer|long|int|short|byte|unsigned(Long|Int|Short|Byte))>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return '0E0'; # zero but true (it's probably ok, but we don't recognize the datatype) | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 24 | ▶ | if ($dt =~ m<http://www.w3.org/2001/XMLSchema#(integer|non(Positive|Negative)Integer|(positive|negative)Integer|long|int|short|byte|unsigned(Long|Int|Short|Byte))>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 18 | ▶ | if ($value =~ m/^([-+])?(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#decimal') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | if ($value =~ m/^([-+])?((\d+)[.]\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | } elsif ($value =~ m/^([-+])?([.]\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#float') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if ($value =~ m/^[-+]?(\d+\.\d*|\.\d+)([Ee][-+]?\d+)?|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 485 | } elsif ($value =~ m/^[-+]?(\d+(\.\d*)?|\.\d+)([Ee][-+]?\d+)|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#double') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | ▶ | if ($value =~ m/^[-+]?((\d+(\.\d*))|(\.\d+))([Ee][-+]?\d+)?|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | } elsif ($value =~ m/^[-+]?((\d+(\.\d*)?)|(\.\d+))([Ee][-+]?\d+)|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if ($value =~ m/^(true|false)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#dateTime') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | if ($value =~ m/^-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||
| 514 | =item C<< is_valid_lexical_form >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | Returns true if the node is of a recognized datatype and has a valid lexical form | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | for that datatype. If the lexical form is invalid, returns false. If the datatype | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | is unrecognized, returns zero-but-true. | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 5 | ▶ | sub is_valid_lexical_form { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid_lexical_form: called CC=15 SCAR=47.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 5 | my $value = $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 5 | my $dt = $self->literal_datatype; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 5 | ▶ | unless ($dt =~ qr<^http://www.w3.org/2001/XMLSchema#(integer|decimal|float|double|boolean|dateTime|non(Positive|Negative)Integer|(positive|negative)Integer|long|int|short|byte|unsigned(Long|Int|Short|Byte))>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | return '0E0'; # zero but true (it's probably ok, but we don't recognize the datatype) | |||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 5 | ▶ | if ($dt =~ m<http://www.w3.org/2001/XMLSchema#(integer|non(Positive|Negative)Integer|(positive|negative)Integer|long|int|short|byte|unsigned(Long|Int|Short|Byte))>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 5 | ▶ | if ($value =~ m/^([-+])?(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#decimal') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | if ($value =~ m/^([-+])?((\d+)([.]\d*)?)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | } elsif ($value =~ m/^([-+])?([.]\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 542 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#float') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | if ($value =~ m/^[-+]?(\d+(\.\d*)?|\.\d+)([Ee][-+]?\d+)?|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#double') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if ($value =~ m/^[-+]?((\d+(\.\d*)?)|(\.\d+))([Ee][-+]?\d+)?|[-+]?INF|NaN$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | if ($value =~ m/^(true|false|0|1)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 560 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#dateTime') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if ($value =~ m/^-?([1-9]\d{3,}|0\d{3})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?|(24:00:00(\.0+)?))(Z|(\+|-)((0\d|1[0-3]):[0-5]\d|14:00))?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 566 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | =item C<< is_numeric_type >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||
| 575 | Returns true if the literal is a known (xsd) numeric type. | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | sub is_numeric_type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_numeric_type: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | return 0 unless ($self->has_datatype); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | my $type = $self->literal_datatype; | |||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if ($type =~ qr<^http://www.w3.org/2001/XMLSchema#(integer|decimal|float|double|non(Positive|Negative)Integer|(positive|negative)Integer|long|int|short|byte|unsigned(Long|Int|Short|Byte))>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 585 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||
| 590 | =item C<< numeric_value >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | Returns the numeric value of the literal (even if the literal isn't a known numeric type. | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | sub numeric_value { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numeric_value: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if ($self->is_numeric_type) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $value = $self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | ▶ | if (looks_like_number($value)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $v = 0 + eval "$value"; ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||
| 603 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | throw RDF::Query::Error::TypeError -text => "Literal with numeric type does not appear to have numeric value."; | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } elsif (not $self->has_datatype) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if (looks_like_number($self->literal_value)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | return 0+$self->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } elsif ($self->literal_datatype eq 'http://www.w3.org/2001/XMLSchema#boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | return ($self->literal_value eq 'true') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 68 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||
| 621 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||