Parser/SAX/Handler.pm

filter: Statementstmt 60.8% 42 / 69 Branchbran 0.0% 0 / 14 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 57.1% 12 / 21 Podpod 93.7% 15 / 16 totaltotal 53.8% 70 / 130 CC 12 SCAR 20.7
CC
12
Cov
48%
entity_decl
20.0
attribute_decl
20.0
new
11.2
CRAP 7.9
« Parser/Base.pm ↑ Summary Parser/SAX.pm »
1 package SVG::Parser::SAX::Handler;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 require 5.004;
6  
7 6 ▶use base qw(XML::SAX::Base SVG::Parser::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use SVG::Parser::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use SVG 2.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 $VERSION="1.03";
12  
13 #-------------------------------------------------------------------------------
14  
15 4 ▶sub new {
Subroutine new: called CC=6 SCAR=24.2
Pod undocumented
16 4 my $proto=shift;
17 4 ▶ my $class=ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
18 4 my %attrs=@_;
19  
20 # pass on non-minus-prefixed attributes to handler
21 4 my %handler_attrs;
22 4 foreach (keys %attrs) {
23 0 ▶ $handler_attrs{$_}=delete $attrs{$_} unless /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^-/ 0 0 0
24 }
25  
26 4 my $self=$class->SUPER::new(%handler_attrs);
27  
28 # minus-prefixed attributes stay here, double-minus to SVG object
29 4 foreach (keys %attrs) {
30 0 ▶ if (/^-(-.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-(-.+)$/) { } 0 0 0
31 0 $self->{__svg_attr}{$1}=$attrs{$_};
32 } else {
33 0 $self->{$_}=$attrs{$_};
34 }
35 }
36  
37 4 return $self;
38 }
39  
40 #-------------------------------------------------------------------------------
41  
42 4 ▶sub start_document {
Subroutine start_document: called CC=1 SCAR=0.0
Pod documented
43 4 my ($self,$document)=@_;
44 4 return $self->SVG::Parser::Base::StartDocument();
45 }
46  
47 160 ▶sub start_element {
Subroutine start_element: called CC=1 SCAR=0.0
Pod documented
48 160 my ($self,$element)=@_;
49  
50 160 my $name=$element->{Name};
51 my %attrs=map {
52 $element->{Attributes}{$_}{Name} => $element->{Attributes}{$_}{Value}
53 160 } keys %{$element->{Attributes}};
54  
55 160 $self->SVG::Parser::Base::StartTag($name,%attrs);
56 }
57  
58 160 ▶sub end_element {
Subroutine end_element: called CC=1 SCAR=0.0
Pod documented
59 160 my ($self,$element)=@_;
60 160 return $self->SVG::Parser::Base::EndTag($element);
61 }
62  
63 260 ▶sub characters {
Subroutine characters: called CC=1 SCAR=0.0
Pod documented
64 260 my ($self,$text)=@_;
65 260 return $self->SVG::Parser::Base::Text($text->{Data});
66 }
67  
68 0 ▶sub start_cdata {
Subroutine start_cdata: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self=shift;
70 0 return $self->SVG::Parser::Base::CdataStart();
71 }
72  
73 0 ▶sub end_cdata {
Subroutine end_cdata: not called CC=1 SCAR=6.9
Pod documented
74 0 my $self=shift;
75 0 return $self->SVG::Parser::Base::CdataEnd();
76 }
77  
78 0 ▶sub processing_instruction {
Subroutine processing_instruction: not called CC=1 SCAR=6.9
Pod documented
79 0 my ($self,$pi)=@_;
80 return $self->SVG::Parser::Base::PI(
81 $pi->{Target},
82 $pi->{Data}
83 0 );
84 }
85  
86 8 ▶sub comment {
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
87 8 my ($self,$comment)=@_;
88 8 return $self->SVG::Parser::Base::Comment($comment->{Data});
89 }
90  
91 4 ▶sub end_document {
Subroutine end_document: called CC=1 SCAR=0.0
Pod documented
92 4 my ($self,$document)=@_;
93 4 return $self->SVG::Parser::Base::FinishDocument();
94 }
95  
96 #-------------------------------------------------------------------------------
97  
98 # handle XML declaration, if present
99 0 ▶sub xml_decl {
Subroutine xml_decl: not called CC=1 SCAR=6.9
Pod documented
100 0 my ($self,$decl)=@_;
101  
102 $self->SVG::Parser::Base::XMLDecl(
103 $decl->{Version},
104 $decl->{Encoding},
105 $decl->{Standalone}
106 0 );
107 }
108  
109 # handle Doctype declaration, if present (and if parser handles it)
110 0 ▶sub doctype_decl {
Subroutine doctype_decl: not called CC=1 SCAR=6.9
Pod documented
111 0 my ($self,$dtd)=@_;
112  
113 $self->SVG::Parser::Base::Doctype(
114 $dtd->{Name},
115 $dtd->{SystemId},
116 $dtd->{PublicId},
117 $dtd->{Internal}
118 0 );
119 }
120  
121 #-------------------------------------------------------------------------------
122  
123 0 ▶sub entity_decl {
Subroutine entity_decl: not called CC=4 SCAR=30.0
Pod documented
124 0 my ($self,$edecl)=@_;
125  
126 0 ▶ if (defined $edecl->{Notation}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $edecl->{'Notation'}) { } 0 0 0
127 # unparsed entity decl
128 $self->SVG::Parser::Base::Unparsed(
129 $edecl->{Name},
130 $edecl->{Value},
131 $edecl->{SystemID},
132 $edecl->{PublicID},
133 $edecl->{Notation},
134 0 0,
135 );
136 } else {
137 # internal/external entity decl
138 0 my $isp=0;
139 0 ▶ if (defined $edecl->{Name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $edecl->{"Name"}) 0 0 0
140 0 ▶ $isp=1 if $edecl->{Name} =~ s/^%//;
Branch: 1 branch
BranchTrueFalseTotal
if $edecl->{"Name"} =~ s/^%// 0 0 0
141 }
142
143 $self->SVG::Parser::Base::Entity(
144 $edecl->{Name},
145 $edecl->{Value},
146 $edecl->{SystemID},
147 $edecl->{PublicID},
148 $edecl->{Notation},
149 0 $isp
150 );
151 }
152 }
153  
154 0 ▶sub notation_decl {
Subroutine notation_decl: not called CC=1 SCAR=6.9
Pod documented
155 0 my ($self,$ndecl)=@_;
156  
157 $self->SVG::Parser::Base::Notation(
158 $ndecl->{Name},
159 $ndecl->{Base},
160 $ndecl->{SystemID},
161 $ndecl->{PublicID},
162 0 );
163 }
164  
165 0 ▶sub element_decl {
Subroutine element_decl: not called CC=1 SCAR=6.9
Pod documented
166 0 my ($self,$edecl)=@_;
167  
168 $self->SVG::Parser::Base::Element(
169 $edecl->{Name},
170 $edecl->{Model}
171 0 );
172 }
173  
174 0 ▶sub attribute_decl {
Subroutine attribute_decl: not called CC=4 SCAR=30.0
Pod documented
175 0 my ($self,$adecl)=@_;
176  
177 $self->SVG::Parser::Base::Attlist(
178 $adecl->{eName},
179 $adecl->{aName},
180 $adecl->{Type},
181 (defined($adecl->{Value}) ? $adecl->{Value} : $adecl->{Mode}),
182 0 ▶ ((defined($adecl->{Mode}) and $adecl->{Mode} eq '#FIXED')?1:0),
Branch: 2 branches
BranchTrueFalseTotal
defined $adecl->{'Value'} ? : 0 0 0
defined $adecl->{'Mode'} && $adecl->{'Mode'} eq '#FIXED' ? : 0 0 0
Condition0%0/3
defined $adecl->{"Mode"} and $adecl->{"Mode"} eq "#FIXED"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $adecl->{"Mode"} and $adecl->{"Mode"} eq "#FIXED"
defined $adecl->{"Mode"} $adecl->{"Mode"} eq "#FIXED"
Truth table0%0/3
A and B
A= defined $adecl->{"Mode"}B= $adecl->{"Mode"} eq "#FIXED"
ABresult
0X0
100
111
183 );
184 }
185  
186 #-------------------------------------------------------------------------------
187  
188 =head1 NAME
189  
190 SVG::Parser::SAX::Handler - SAX handler class for SVG documents
191  
192 =head1 DESCRIPTION
193  
194 This module provides the handlers for constructing an SVG document object when
195 using SVG::Parser::SAX. See L<SVG::Parser::SAX> for more information.
196  
197 =head1 AUTHOR
198  
199 Peter Wainwright, peter.wainwright@cybrid.net
200  
201 =head1 SEE ALSO
202  
203 L<SVG::Parser>, L<SVG::Parser::SAX>
204  
205 =cut
206  
207 6 1;
« Parser/Base.pm ↑ Summary Parser/SAX.pm »