AtteanX/Parser/SPARQLXML/SAXHandler.pm

filter: Statementstmt 85.1% 109 / 128 Branchbran 70.8% 34 / 48 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 79.4% 162 / 204 CC 28 SCAR 33.0
CC
28
Cov
79%
end_element
45.9
start_element
3.1
new
3.0
CRAP 27.2
« AtteanX/Serializer/TurtleTokens.pm ↑ Summary AtteanX/Parser/Turtle/Token.pm »
1 # AtteanX::Parser::SPARQLXML::SAXHandler
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 AtteanX::Parser::SPARQLXML::SAXHandler - XML parser for SPARQL XML Results format
7  
8 =head1 VERSION
9  
10 This document describes AtteanX::Parser::SPARQLXML::SAXHandler version 0.041
11  
12 =head1 STATUS
13  
14 This module's API and functionality should be considered unstable.
15 In the future, this module may change in backwards-incompatible ways,
16 or be removed entirely.
17  
18 =head1 SYNOPSIS
19  
20 use AtteanX::Parser::SPARQLXML::SAXHandler;
21  
22 =head1 METHODS
23  
24 =over 4
25  
26 =cut
27  
28 package AtteanX::Parser::SPARQLXML::SAXHandler 0.041;
29  
30 5 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 ▶use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use base qw(XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 5 ▶use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 5 my %strings;
40 my %tagstack;
41 5 my %results;
42 5 my %values;
43 5 my %bindings;
44 5 my %booleans;
45 5 my %variables;
46 5 my %has_head;
47 5 my %has_end;
48 5 my %result_count;
49 5 my %result_handlers;
50 5 my %config;
51 5 my %triples;
52  
53 5 my %expecting_string = map { $_ => 1 } qw(boolean bnode uri literal);
54  
55 =item C<< new ( [ \&handler ] ) >>
56  
57 Returns a new XML::SAX handler object. If C<< &handler >> is supplied, it will
58 be called with a variable bindings object as each is parsed, bypassing the
59 normal process of collecting the results for retrieval via an iterator object.
60  
61 =cut
62  
63 4 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
64 4 my $class = shift;
65 4 my $self = $class->SUPER::new();
66 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 0 4
67 4 my $addr = refaddr( $self );
68 4 my $code = shift;
69 4 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
04
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
70 4 $result_handlers{ $addr } = $code;
71 4 $config{ $addr } = { %$args };
72 }
73 4 return $self;
74 }
75  
76 =begin private
77  
78 =item C<< start_element >>
79  
80 =cut
81  
82 75 ▶sub start_element {
Subroutine start_element: called CC=3 SCAR=11.2
Pod documented
83 75 my $self = shift;
84 75 my $el = shift;
85 75 my $tag = $el->{LocalName};
86 75 my $addr = refaddr( $self );
87
88 75 unshift( @{ $tagstack{ $addr } }, [$tag, $el] );
89 75 ▶ if ($expecting_string{ $tag }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_string{$tag}) 21 54 75
90 21 $strings{ $addr } = '';
91 }
92
93 75 ▶ if ($tag eq 'triple') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "triple") 0 75 75
94 0 push(@{ $triples{ $addr } }, {});
95 }
96 }
97  
98 =item C<< end_element >>
99  
100 =cut
101  
102 75 ▶sub end_element {
Subroutine end_element: called CC=23 SCAR=38.3
Pod documented
103 75 my $self = shift;
104 75 my $class = ref($self);
105 75 my $eel = shift;
106 75 my $addr = refaddr( $self );
107 75 my $string = $strings{ $addr };
108 75 my $taginfo = shift( @{ $tagstack{ $addr } } );
109 75 my ($tag, $el) = @$taginfo;
110
111 75 ▶ if ($tag eq 'head') {
Branch: 13 branches
BranchTrueFalseTotal
if ($tag eq 'head') { } 4 71 75
elsif ($tag eq 'sparql') { } 4 67 71
elsif ($tag eq 'variable') { } 14 53 67
elsif ($tag eq 'boolean') { } 0 53 53
elsif ($tag eq 'binding') { } 21 32 53
elsif ($tag eq 'result') { } 7 25 32
elsif ($tag eq 'bnode') { } 2 23 25
elsif ($tag eq 'uri') { } 11 12 23
elsif ($tag eq 'literal') { } 8 4 12
elsif ($tag eq 'subject') { } 0 4 4
elsif ($tag eq 'predicate') { } 0 4 4
elsif ($tag eq 'object') { } 0 4 4
elsif ($tag eq 'triple') { } 0 4 4
112 4 $has_head{ $addr } = 1;
113 4 ▶ if (my $code = $result_handlers{ $addr }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $result_handlers{$addr}) 4 0 4
114 4 ▶ if ($config{ $addr }{ variables }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config{$addr}{"variables"}) 0 4 4
115 0 $code->( $variables{ $addr } );
116 }
117 }
118 } elsif ($tag eq 'sparql') {
119 4 $has_end{ $addr } = 1;
120 } elsif ($tag eq 'variable') {
121 14 push( @{ $variables{ $addr } }, $el->{Attributes}{'{}name'}{Value});
122 } elsif ($tag eq 'boolean') {
123 0 ▶ $booleans{ $addr } = ($string eq 'true') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$string eq 'true' ? : 0 0 0
124 0 ▶ if ($string =~ /^(?:true|false)$/ and my $code = $result_handlers{ $addr }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^(?:true|false)$/u and my $code = $result_handlers{$addr}) 0 0 0
Condition0%0/3
$string =~ /^(?:true|false)$/u and my $code = $result_handlers{$addr}
!ll&&!rl&&r
000
MC/DC0%0/2
$string =~ /^(?:true|false)$/u and my $code = $result_handlers{$addr}
$string =~ /^(?:true|false)$/u my $code = $result_handlers{$addr}
Truth table0%0/3
A and B
A= $string =~ /^(?:true|false)$/uB= my $code = $result_handlers{$addr}
ABresult
0X0
100
111
125 0 $code->( Attean::Literal->$string() );
126 }
127 } elsif ($tag eq 'binding') {
128 21 my $name = $el->{Attributes}{'{}name'}{Value};
129 21 my $value = delete( $values{ $addr } );
130 21 $bindings{ $addr }{ $name } = $value;
131 } elsif ($tag eq 'result') {
132 7 ▶ my $result = delete( $bindings{ $addr } ) || {};
Condition50%1/2
delete $bindings{$addr} || {}
l!l
70
MC/DC0%0/1
delete $bindings{$addr} || {}
delete $bindings{$addr}
Truth table50%1/2
A
A= delete $bindings{$addr}
Aresult
11
00
133 7 $result_count{ $addr }++;
134 7 my $vb = Attean::Result->new( bindings => $result );
135 7 ▶ if (my $code = $result_handlers{ $addr }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $result_handlers{$addr}) { } 7 0 7
136 7 $code->( $vb );
137 } else {
138 0 push( @{ $results{ $addr } }, $vb );
139 }
140 } elsif ($tag eq 'bnode') {
141 2 $values{ $addr } = Attean::Blank->new( $string );
142 } elsif ($tag eq 'uri') {
143 11 $values{ $addr } = Attean::IRI->new( $string );
144 } elsif ($tag eq 'literal') {
145 8 my ($lang, $dt);
146 8 ▶ if (my $dtinf = $el->{Attributes}{'{}datatype'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $dtinf = $el->{'Attributes'}{'{}datatype'}) { } 5 3 8
elsif (my $langinf = $el->{'Attributes'}{'{http://www.w3.org/XML/1998/namespace}lang'}) { } 2 1 3
147 5 $dt = $dtinf->{Value};
148 5 $values{ $addr } = Attean::Literal->new( value => $string, datatype => $dt );
149 } elsif (my $langinf = $el->{Attributes}{'{http://www.w3.org/XML/1998/namespace}lang'}) {
150 2 $lang = $langinf->{Value};
151 2 $values{ $addr } = Attean::Literal->new( value => $string, language => $lang );
152 } else {
153 1 $values{ $addr } = Attean::Literal->new( value => $string );
154 }
155 } elsif ($tag eq 'subject') {
156 0 my $value = delete( $values{ $addr } );
157 0 $triples{ $addr }[-1]{$tag} = $value;
158 } elsif ($tag eq 'predicate') {
159 0 my $value = delete( $values{ $addr } );
160 0 $triples{ $addr }[-1]{$tag} = $value;
161 } elsif ($tag eq 'object') {
162 0 my $value = delete( $values{ $addr } );
163 0 $triples{ $addr }[-1]{$tag} = $value;
164 } elsif ($tag eq 'triple') {
165 0 my $data = pop(@{ $triples{ $addr } });
166 0 my $t = Attean::Triple->new( %{ $data } );
167 0 $values{ $addr } = $t;
168 }
169 }
170  
171 =item C<< characters >>
172  
173 =cut
174  
175 100 ▶sub characters {
Subroutine characters: called CC=2 SCAR=6.9
Pod documented
176 100 my $self = shift;
177 100 my $data = shift;
178 100 my $addr = refaddr( $self );
179
180 100 my $tag = $self->_current_tag;
181 100 ▶ if ($expecting_string{ $tag }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_string{$tag}) 21 79 100
182 21 my $chars = $data->{Data};
183 21 $strings{ $addr } .= $chars;
184 }
185 }
186  
187 100 ▶sub _current_tag {
Subroutine _current_tag: called CC=1 SCAR=0.0
188 100 my $self = shift;
189 100 my $addr = refaddr( $self );
190 100 return $tagstack{ $addr }[0][0];
191 }
192  
193 4 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
194 4 my $self = shift;
195 4 my $addr = refaddr( $self );
196 4 delete $strings{ $addr };
197 4 delete $results{ $addr };
198 4 delete $tagstack{ $addr };
199 4 delete $values{ $addr };
200 4 delete $bindings{ $addr };
201 4 delete $booleans{ $addr };
202 4 delete $variables{ $addr };
203 4 delete $has_head{ $addr };
204 4 delete $has_end{ $addr };
205 4 delete $result_count{ $addr };
206 4 delete $result_handlers{ $addr };
207 4 delete $config{ $addr };
208 }
209  
210  
211 5 1;
212  
213 __END__
« AtteanX/Serializer/TurtleTokens.pm ↑ Summary AtteanX/Parser/Turtle/Token.pm »