line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::Parser::SAX; |
2
|
6
|
|
|
6
|
|
18860
|
use strict; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
216
|
|
3
|
6
|
|
|
6
|
|
32
|
use Carp; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
465
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require 5.004; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
3675
|
use XML::SAX; |
|
6
|
|
|
|
|
42612
|
|
|
6
|
|
|
|
|
284
|
|
8
|
6
|
|
|
6
|
|
4152
|
use SVG::Parser::Base; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
205
|
|
9
|
6
|
|
|
6
|
|
3745
|
use SVG::Parser::SAX::Handler; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
249
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
35
|
use vars qw(@ISA $VERSION); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
3223
|
|
12
|
|
|
|
|
|
|
@ISA=qw(SVG::Parser::Base); # this changes once the parser type is known |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION="1.03"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
SVG::Parser::SAX - XML SAX Parser for SVG documents |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
25
|
|
|
|
|
|
|
use strict; |
26
|
|
|
|
|
|
|
use SVG::Parser::SAX; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
die "Usage: $0 \n" unless @ARGV; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $xml; |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
local $/=undef; |
33
|
|
|
|
|
|
|
$xml=<>; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $parser=new SVG::Parser::SAX(-debug => 1); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $svg=$parser->parse($xml); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
print $svg->xmlify; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SVG::Parser::SAX is the SAX-based parser module used by SVG::Parser when an |
45
|
|
|
|
|
|
|
underlying XML::SAX-based parser is selected. It may also be used directly, as shown |
46
|
|
|
|
|
|
|
in the synopsis above. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Use SVG::Parser to retain maximum flexibility as to which underlying parser is chosen. |
49
|
|
|
|
|
|
|
Use SVG::Parser::SAX to supply SAX-specific parser options or where the presence |
50
|
|
|
|
|
|
|
of a functional XML::SAX parser is known and/or preferred. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 EXPORTS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
None. However, a preferred SAX parser implementations can be specified by |
55
|
|
|
|
|
|
|
passing the package name to SVG::Parser::SAX in the import list. For example: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use SVG::Parser::SAX qw(XML::LibXML::SAX::Parser); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
A minimum version number may be additionally suppied as a second import item: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use SVG::Parser::SAX (XML::LibXML::SAX::Parser => 1.40); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This overrides the automatic selection of a suitable SAX parser. To try several |
64
|
|
|
|
|
|
|
different parsers in turn, use the SVG::Parser module instead and restrict it |
65
|
|
|
|
|
|
|
to only try SAX-based parsers. To make use of the automatic selection mechanism, |
66
|
|
|
|
|
|
|
omit the import list. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
When loaded via SVG::Parser, this parent class may be specified by placing it |
69
|
|
|
|
|
|
|
after the '=' in a parser specification: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
See L for more details. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 EXAMPLES |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
See C in the examples directory of the distribution. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Peter Wainwright, peter.wainwright@cybrid.net |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
L |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub new { |
90
|
4
|
|
|
4
|
0
|
1220
|
my $proto=shift; |
91
|
4
|
|
33
|
|
|
32
|
my $class=ref($proto) || $proto; |
92
|
4
|
|
|
|
|
11
|
my %attrs=@_; |
93
|
|
|
|
|
|
|
|
94
|
4
|
|
|
|
|
42
|
my $handler=SVG::Parser::SAX::Handler->new(%attrs); |
95
|
4
|
|
|
|
|
41
|
my $self=XML::SAX::ParserFactory->parser( |
96
|
|
|
|
|
|
|
Handler => $handler, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# first time through set up the @ISA for the package |
100
|
4
|
50
|
|
|
|
2593732
|
@ISA=(ref($self),"SVG::Parser::Base") if @ISA==1; |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
37
|
return bless $self,$class; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
106
|
|
|
|
|
|
|
# Import method to change default inheritance, if required |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub import { |
109
|
2
|
|
|
2
|
|
18
|
my $package=shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# permit an alternative XML::SAX parser to be our parser |
112
|
2
|
50
|
|
|
|
31
|
if (@_) { |
113
|
0
|
|
|
|
|
0
|
my ($superclass,$version)=@_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# select specific XML::SAX parser: 'pkg' or 'pkg => version' |
116
|
0
|
0
|
|
|
|
0
|
if ($version) { |
117
|
0
|
0
|
|
|
|
0
|
$XML::SAX::ParserPackage="$superclass ($version)" if eval qq[ |
118
|
|
|
|
|
|
|
use $superclass $version; |
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
]; |
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
0
|
|
|
|
0
|
$XML::SAX::ParserPackage=$superclass if eval qq[ |
123
|
|
|
|
|
|
|
use $superclass; |
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
]; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
131
|
|
|
|
|
|
|
# Expat -> SAX compatability |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# parsefile take a filename or a file handle, parse_file takes a file handle |
134
|
|
|
|
|
|
|
sub parsefile { |
135
|
3
|
|
|
3
|
0
|
682
|
my ($self,$source,@args)=@_; |
136
|
|
|
|
|
|
|
|
137
|
3
|
|
|
|
|
41
|
my $type=$self->identify($source); |
138
|
3
|
50
|
|
|
|
48
|
return "" if $type eq $self->ARG_IS_INVALID; |
139
|
|
|
|
|
|
|
|
140
|
3
|
100
|
|
|
|
53
|
if ($type eq $self->ARG_IS_STRING) { |
|
|
50
|
|
|
|
|
|
141
|
2
|
|
|
|
|
7
|
local(*FH); |
142
|
2
|
50
|
|
|
|
103
|
open FH,$source or croak "Couldn't open $: $!"; |
143
|
2
|
|
|
|
|
29
|
return $self->SUPER::parse_file(*FH,@_); |
144
|
|
|
|
|
|
|
} elsif ($type eq $self->ARG_IS_HASHRF) { |
145
|
0
|
|
|
|
|
0
|
return $self->SUPER::parse({ %$source,@args }); |
146
|
|
|
|
|
|
|
} else { |
147
|
1
|
|
|
|
|
11
|
return $self->SUPER::parse_file($source,@_); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
*parse_file=\&parsefile; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |