| 1 | # RDF::Trine::Parser::NTriples | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | RDF::Trine::Parser::NTriples - N-Triples Parser | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | This document describes RDF::Trine::Parser::NTriples version 1.019 | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | use RDF::Trine::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | my $parser = RDF::Trine::Parser->new( 'ntriples' ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | $parser->parse_into_model( $base_uri, $data, $model ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||||||||||||||||||||||||||||||||
| 25 | L<RDF::Trine::Parser> class. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | package RDF::Trine::Parser::NTriples; | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 68 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 68 | ▶ | use base qw(RDF::Trine::Parser); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 68 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 68 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 68 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 68 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 68 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 68 | ▶ | use RDF::Trine qw(literal); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 68 | ▶ | use RDF::Trine::Node; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 68 | ▶ | use RDF::Trine::Statement; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 68 | ▶ | use RDF::Trine::Error qw(:try); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 68 | our ($VERSION); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 68 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 68 | $VERSION = '1.019'; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 68 | $RDF::Trine::Parser::parser_names{ 'ntriples' } = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 68 | foreach my $ext (qw(nt)) { | |||||||||||||||||||||||||||||||||||||||||
| 57 | 68 | $RDF::Trine::Parser::file_extensions{ $ext } = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 68 | my $class = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 68 | $RDF::Trine::Parser::canonical_media_types{ $class } = 'text/plain'; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 68 | foreach my $type (qw(text/plain)) { | |||||||||||||||||||||||||||||||||||||||||
| 62 | 68 | $RDF::Trine::Parser::media_types{ $type } = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 68 | $RDF::Trine::Parser::format_uris{ 'http://www.w3.org/ns/formats/N-Triples' } = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =item C<< new >> | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 394 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 394 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 394 | my $self = bless( {@_}, $class); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 394 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | =item C<< parse_into_model ( $base_uri, $data, $model [, context => $context] ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | Parses the bytes in C<< $data >>. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | For each RDF statement parsed, will call C<< $model->add_statement( $statement ) >>. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | =item C<< parse_file_into_model ( $base_uri, $fh, $model [, context => $context] ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | Parses all data read from the filehandle C<< $fh >>. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | For each RDF statement parsed, will call C<< $model->add_statement( $statement ) >>. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =item C<< parse ( $base_uri, $rdf, \&handler ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 24 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 24 | my $base = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 24 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | my $handler = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | open( my $fh, '<:encoding(UTF-8)', \$string ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 24 | return $self->parse_file( $base, $fh, $handler ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =item C<< parse_node ( $string, $base ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | Returns the RDF::Trine::Node object corresponding to the node whose N-Triples | ||||||||||||||||||||||||||||||||||||||||||
| 108 | serialization is found at the beginning of C<< $string >>. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub parse_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $uri = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $n = $self->_eat_node( $uri, 0, $string ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =item C<< parse_file ( $base, $fh, \&handler ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 412 | ▶ | sub parse_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=10 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 412 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 412 | my $base = shift; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 412 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 412 | my $handler = shift; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 412 | ▶ | unless (ref($fh)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $filename = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | undef $fh; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | open( $fh, '<:encoding(UTF-8)', $filename ) or throw RDF::Trine::Error::ParserError -text => $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 412 | my $lineno = 0; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 412 | ▶ | while (defined(my $line = <$fh>)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 3870 | LINE: | |||||||||||||||||||||||||||||||||||||||||
| 140 | ($line, my @extra) = split(/\r\n|\r|\n/, $line, 2); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 3870 | $lineno++; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 3870 | ▶ | next unless (defined($line) and length($line)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $line and length $line
MC/DC100%2/2
defined $line and length $line
defined $line
length $line
Truth table100%3/3
A and B
A= defined $lineB= length $line
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 3019 | ▶ | next unless ($line =~ /\S/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 3017 | chomp($line); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 3017 | $line =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 3017 | $line =~ s/\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 3017 | ▶ | next if ($line =~ /^#/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 750 | my @nodes = (); | |||||||||||||||||||||||||||||||||||||||||
| 151 | 750 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 750 | ▶ | while (my $n = $self->_eat_node( $base, $lineno, $line )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 2257 | push(@nodes, $n); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 2257 | $line =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 750 | }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 750 | $line =~ s/^\s//g; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 750 | ▶ | unless ($line eq '.') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | # Carp::cluck 'N-Triples parser failed: ' . Dumper(\@nodes, $line); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | throw RDF::Trine::Error::ParserError -text => "Missing expected '.' at line $lineno"; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 750 | $self->_emit_statement( $handler, \@nodes, $lineno ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 750 | ▶ | if (@extra) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 750 | $line = shift(@extra); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 750 | goto LINE; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 742 | ▶ | sub _emit_statement { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_statement: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 742 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 742 | my $handler = shift; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 742 | my $nodes = shift; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 742 | my $lineno = shift; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 742 | my $st; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 742 | ▶ | if (scalar(@$nodes) == 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 742 | ▶ | if ($self->{canonicalize}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 6 | ▶ | if ($nodes->[2]->isa('RDF::Trine::Node::Literal') and $nodes->[2]->has_datatype) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nodes->[2]->isa("RDF::Trine::Node::Literal") and $nodes->[2]->has_datatype
MC/DC50%1/2
$nodes->[2]->isa("RDF::Trine::Node::Literal") and $nodes->[2]->has_datatype
$nodes->[2]->isa("RDF::Trine::Node::Literal")
$nodes->[2]->has_datatype
Truth table66%2/3
A and B
A= $nodes->[2]->isa("RDF::Trine::Node::Literal")B= $nodes->[2]->has_datatype
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 5 | my $value = $nodes->[2]->literal_value; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 5 | my $dt = $nodes->[2]->literal_datatype; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 5 | my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value( $value, $dt, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 5 | $nodes->[2] = literal( $canon, undef, $dt ); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 742 | $st = RDF::Trine::Statement->new( @$nodes ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | # } elsif (scalar(@$nodes) == 4) { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # $st = RDF::Trine::Statement::Quad->new( @$nodes ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # warn Dumper($nodes); | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Not valid N-Triples data at line $lineno]; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 742 | $handler->( $st ); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 3007 | ▶ | sub _eat_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eat_node: called CC=23 SCAR=31.6
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 3007 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 3007 | my $base = shift; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 3007 | my $lineno = shift; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 3007 | $_[0] =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 3007 | ▶ | return unless length($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3007 | my $char = substr($_[0], 0, 1); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 3007 | ▶ | return if ($char eq '.'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 2257 | ▶ | if ($char eq '<') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1649 | my ($uri) = $_[0] =~ m/^<([^>]*)>/; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 1649 | substr($_[0], 0, length($uri)+2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 1649 | return RDF::Trine::Node::Resource->new( _unescape($uri, $lineno) ); | |||||||||||||||||||||||||||||||||||||||||
| 209 | } elsif ($char eq '_') { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 282 | my ($name) = $_[0] =~ m/^_:([A-Za-z][A-Za-z0-9]*)/; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 282 | substr($_[0], 0, length($name)+2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 282 | return RDF::Trine::Node::Blank->new( $name ); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } elsif ($char eq '"') { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 326 | substr($_[0], 0, 1) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 326 | my $value = decode('utf8', ''); | |||||||||||||||||||||||||||||||||||||||||
| 216 | 326 | ▶ | while (length($_[0]) and substr($_[0], 0, 1) ne '"') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $_[0] and substr($_[0], 0, 1) ne "\""
MC/DC50%1/2
length $_[0] and substr($_[0], 0, 1) ne "\""
length $_[0]
substr($_[0], 0, 1) ne "\""
Truth table66%2/3
A and B
A= length $_[0]B= substr($_[0], 0, 1) ne "\""
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 379 | ▶ | while ($_[0] =~ m/^([^"\\]+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 350 | $value .= $1; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 350 | substr($_[0],0,length($1)) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 379 | ▶ | if (substr($_[0],0,1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 98 | ▶ | while ($_[0] =~ m/^\\(.)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 211 | ▶ | if ($1 eq 't') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 15 | $value .= "\t"; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 15 | substr($_[0],0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } elsif ($1 eq 'r') { | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | $value .= "\r"; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | substr($_[0],0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } elsif ($1 eq 'n') { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 44 | $value .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 44 | substr($_[0],0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } elsif ($1 eq '"') { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 19 | $value .= '"'; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 19 | substr($_[0],0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } elsif ($1 eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | $value .= "\\"; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | substr($_[0],0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } elsif ($1 eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 99 | ▶ | $_[0] =~ m/^\\u([0-9A-Fa-f]{4})/ or throw RDF::Trine::Error::ParserError -text => qq[Bad N-Triples \\u escape at line $lineno, near "$_[0]"]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 99 | $value .= chr(oct('0x' . $1)); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 99 | substr($_[0],0,6) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } elsif ($1 eq 'U') { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 27 | ▶ | $_[0] =~ m/^\\U([0-9A-Fa-f]{8})/ or throw RDF::Trine::Error::ParserError -text => qq[Bad N-Triples \\U escape at line $lineno, near "$_[0]"]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 27 | $value .= chr(oct('0x' . $1)); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 27 | substr($_[0],0,10) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Not valid N-Triples escape character '\\$1' at line $lineno, near "$_[0]"]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 326 | ▶ | if (substr($_[0],0,1) eq '"') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 326 | substr($_[0],0,1) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Ending double quote not found at line $lineno]; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 326 | ▶ | if ($_[0] =~ m/^@([a-z]+(-[a-zA-Z0-9]+)*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 20 | my $lang = $1; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 20 | substr($_[0],0,1+length($lang)) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 20 | return RDF::Trine::Node::Literal->new($value, $lang); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } elsif (substr($_[0],0,3) eq '^^<') { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 89 | substr($_[0],0,3) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 89 | my ($uri) = $_[0] =~ m/^([^>]*)>/; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 89 | substr($_[0], 0, length($uri)+1) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 89 | return RDF::Trine::Node::Literal->new($value, undef, $uri); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 217 | return RDF::Trine::Node::Literal->new($value); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Not valid N-Triples node start character '$char' at line $lineno, near "$_[0]"]; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 1649 | ▶ | sub _unescape { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unescape: called CC=18 SCAR=37.1
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1649 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 1649 | my $lineno = shift; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1649 | my $value = ''; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 1649 | ▶ | while (length($string)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 1653 | ▶ | while ($string =~ m/^([^\\]+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 1653 | $value .= $1; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 1653 | substr($string,0,length($1)) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 1653 | ▶ | if (length($string)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 11 | ▶ | if ($string eq '\\') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Backslash in N-Triples node without escaped character at line $lineno]; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 11 | ▶ | if ($string =~ m/^\\([tbnrf"'uU])/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 11 | ▶ | while ($string =~ m/^\\([tbnrf"'uU])/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 78 | ▶ | if ($1 eq 't') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $value .= "\t"; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } elsif ($1 eq 'b') { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $value .= "\b"; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } elsif ($1 eq 'n') { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $value .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } elsif ($1 eq 'r') { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $value .= "\r"; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } elsif ($1 eq 'f') { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $value .= "\f"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } elsif ($1 eq '"') { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $value .= '"'; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } elsif ($1 eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $value .= "\\"; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | substr($string,0,2) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } elsif ($1 eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 74 | ▶ | $string =~ m/^\\u([0-9A-F]{4})/ or throw RDF::Trine::Error::ParserError -text => qq[Bad N-Triples \\u escape at line $lineno, near "$string"]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 74 | $value .= chr(oct('0x' . $1)); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 74 | substr($string,0,6) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } elsif ($1 eq 'U') { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | ▶ | $string =~ m/^\\U([0-9A-F]{8})/ or throw RDF::Trine::Error::ParserError -text => qq[Bad N-Triples \\U escape at line $lineno, near "$string"]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | $value .= chr(oct('0x' . $1)); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | substr($string,0,10) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $esc = substr($string, 0, 2); | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | throw RDF::Trine::Error::ParserError -text => qq[Not a valid N-Triples escape sequence '$esc' at line $lineno, near "$string"]; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 1649 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 68 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | __END__ | ||||||||||||||||||||||||||||||||||||||||||