line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Directory::SAX; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.005_03; |
4
|
1
|
50
|
|
1
|
|
44609
|
BEGIN { require warnings if $] >= 5.006; } |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
92
|
|
8
|
1
|
|
|
1
|
|
5
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
9
|
1
|
|
|
1
|
|
6
|
use XML::Directory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
10
|
1
|
|
|
1
|
|
6
|
use XML::SAX::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1599
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@XML::Directory::SAX::ISA = qw(XML::SAX::Base XML::Directory); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
0
|
10
|
my $proto = shift; |
16
|
1
|
|
33
|
|
|
11
|
my $class = ref($proto) || $proto; |
17
|
1
|
50
|
|
|
|
6
|
my $options = ($#_ == 0) ? shift : { @_ }; |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
22232
|
$options->{path} = cwd unless $options->{path}; |
20
|
1
|
50
|
|
|
|
32
|
$options->{details} = 2 unless $options->{details}; |
21
|
1
|
50
|
|
|
|
14
|
$options->{depth} = 1000 unless defined $options->{depth}; |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
|
|
|
104
|
$options->{path} = cwd if $options->{path} eq '.'; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
15
|
$options->{path} = File::Spec::Functions::canonpath($options->{path}); |
26
|
1
|
|
|
|
|
6
|
$options->{error} = 0; |
27
|
1
|
|
|
|
|
7
|
$options->{catch_error} = 0; |
28
|
1
|
|
|
|
|
8
|
$options->{ns_enabled} = 0; |
29
|
1
|
|
|
|
|
3
|
$options->{rdf_enabled} = 0; |
30
|
1
|
|
|
|
|
9
|
$options->{n3_index} = ''; |
31
|
1
|
|
|
|
|
7
|
$options->{ns_uri} = 'http://gingerall.org/directory/1.0/'; |
32
|
1
|
|
|
|
|
15
|
$options->{ns_prefix} = 'xd'; |
33
|
1
|
|
|
|
|
3
|
$options->{encoding} = 'utf-8'; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
18
|
my $self = bless $options, $class; |
36
|
|
|
|
|
|
|
# turn NS processing on by default |
37
|
1
|
|
|
|
|
41
|
$self->set_feature('http://xml.org/sax/features/namespaces', 1); |
38
|
1
|
|
|
|
|
119
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# -------------------------------------------------- |
42
|
|
|
|
|
|
|
# XML::SAX compliant methods |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub parse_dir { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my $dir = shift; |
47
|
0
|
0
|
|
|
|
|
$dir = $self->{path} unless $dir; |
48
|
0
|
|
|
|
|
|
my $parse_options = $self->get_options(@_); |
49
|
0
|
|
|
|
|
|
$parse_options->{Source}{ByteStream} = $dir; |
50
|
0
|
|
|
|
|
|
$self->{path} = $dir; |
51
|
0
|
0
|
0
|
|
|
|
if ($parse_options->{Handler} or $parse_options->{ContentHandler} |
|
|
|
0
|
|
|
|
|
52
|
|
|
|
|
|
|
or $parse_options->{DocumentHandler}) { |
53
|
0
|
|
|
|
|
|
return $self->XML::SAX::Base::parse($parse_options); |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
|
$self->doError(8,''); |
56
|
0
|
|
|
|
|
|
return -1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub parse_file { |
62
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
63
|
0
|
|
|
|
|
|
return $self->parse_dir(@_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _parse_bytestream { |
67
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->XML::Directory::parse; |
70
|
0
|
|
|
|
|
|
return $self->{ret}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _parse_systemid { |
74
|
0
|
|
|
0
|
|
|
my $self = shift; |
75
|
0
|
|
|
|
|
|
$self->doError(4,'SystemId'); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _parse_string { |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
$self->doError(4,'String'); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _parse_characterstream { |
84
|
0
|
|
|
0
|
|
|
my $self = shift; |
85
|
0
|
|
|
|
|
|
$self->doError(4,'CharacterStream'); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# -------------------------------------------------- |
89
|
|
|
|
|
|
|
# old parse() method for backward compatibility |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub parse { |
92
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
93
|
0
|
|
|
|
|
|
return $self->parse_dir(@_); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# -------------------------------------------------- |
97
|
|
|
|
|
|
|
# private methods |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub doStartDocument { |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
$self->start_document; |
102
|
0
|
0
|
|
|
|
|
if ($self->{doctype}) { |
103
|
0
|
|
|
|
|
|
$self->_start_dtd; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub doEndDocument { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
$self->{ret} = $self->end_document; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub doStartElement { |
113
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $attr, $qname) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my %attributes; |
116
|
0
|
|
|
|
|
|
foreach (@$attr) { |
117
|
0
|
|
|
|
|
|
$attributes{"{}$_->[0]"} = { |
118
|
|
|
|
|
|
|
Name => $_->[0], |
119
|
|
|
|
|
|
|
LocalName => $_->[0], |
120
|
|
|
|
|
|
|
Prefix => '', |
121
|
|
|
|
|
|
|
NamespaceURI => '', |
122
|
|
|
|
|
|
|
Value => $_->[1], |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $uri = $self->_ns_uri; |
127
|
0
|
|
|
|
|
|
my $prefix = ''; |
128
|
0
|
0
|
|
|
|
|
$prefix = $self->_ns_prefix unless $qname; |
129
|
0
|
|
|
|
|
|
my $name = $tag; |
130
|
0
|
0
|
|
|
|
|
$name = "$prefix:$tag" if $prefix; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
$self->start_element({ |
133
|
|
|
|
|
|
|
Name => $name, |
134
|
|
|
|
|
|
|
LocalName => $tag, |
135
|
|
|
|
|
|
|
Prefix => $prefix, |
136
|
|
|
|
|
|
|
NamespaceURI => $uri, |
137
|
|
|
|
|
|
|
Attributes => \%attributes, |
138
|
|
|
|
|
|
|
}); |
139
|
|
|
|
|
|
|
}; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub doEndElement { |
142
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $qname) = @_; |
143
|
0
|
|
|
|
|
|
my $uri = $self->_ns_uri; |
144
|
0
|
|
|
|
|
|
my $prefix = ''; |
145
|
0
|
0
|
|
|
|
|
$prefix = $self->_ns_prefix unless $qname; |
146
|
0
|
|
|
|
|
|
my $name = $tag; |
147
|
0
|
0
|
|
|
|
|
$name = "$prefix:$tag" if $prefix; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$self->end_element({ |
150
|
|
|
|
|
|
|
Name => $name, |
151
|
|
|
|
|
|
|
LocalName => $tag, |
152
|
|
|
|
|
|
|
Prefix => $prefix, |
153
|
|
|
|
|
|
|
NamespaceURI => $uri, |
154
|
|
|
|
|
|
|
}); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub doElement { |
158
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $attr, $value, $qname) = @_; |
159
|
0
|
|
|
|
|
|
$self->doStartElement($tag, $attr, $qname); |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
$self->characters({Data => $value }) if $value; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$self->doEndElement($tag, $qname); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub doError { |
167
|
0
|
|
|
0
|
0
|
|
my ($self, $n, $par) = @_; |
168
|
0
|
|
|
|
|
|
my $msg = $self->_msg($n); |
169
|
0
|
|
|
|
|
|
$msg = "[Error $n] $msg: $par"; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
0
|
|
|
|
unless ($self->{catch_error} && $self->{ErrorHandler}) { |
172
|
0
|
|
|
|
|
|
croak "$msg\n" |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
} else { |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$msg =~ s/&/&/g; |
177
|
0
|
|
|
|
|
|
$msg =~ s/</g; |
178
|
0
|
|
|
|
|
|
$msg =~ s/>/>/g; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
$self->{error} = $n; |
181
|
0
|
|
|
|
|
|
$self->SUPER::fatal_error({Message => $msg}); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _ns_prefix { |
186
|
0
|
|
|
0
|
|
|
my $self = shift; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my $pref = ''; |
189
|
0
|
0
|
0
|
|
|
|
if ($self->{ns_enabled} && $self->{ns_prefix}) { |
190
|
0
|
|
|
|
|
|
$pref = "$self->{ns_prefix}"; |
191
|
|
|
|
|
|
|
} |
192
|
0
|
|
|
|
|
|
return $pref; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _ns_uri { |
196
|
0
|
|
|
0
|
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $uri = ''; |
199
|
0
|
0
|
0
|
|
|
|
if ($self->{ns_enabled} && $self->{ns_uri}) { |
200
|
0
|
|
|
|
|
|
$uri = "$self->{ns_uri}"; |
201
|
|
|
|
|
|
|
} |
202
|
0
|
|
|
|
|
|
return $uri; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub _start_dtd { |
206
|
0
|
|
|
0
|
|
|
my $self = shift; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
my $public_id = "-//GA//DTD XML-Directory 1.0 Level_DET_//EN"; |
209
|
0
|
|
|
|
|
|
my $system_id = "http://www.gingerall.org/dtd/XML-Directory/1.0/dirtree-level_DET_.dtd"; |
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
if ($self->{details}) { |
212
|
0
|
|
|
|
|
|
$public_id =~ s/_DET_/$self->{details}/; |
213
|
0
|
|
|
|
|
|
$system_id =~ s/_DET_/$self->{details}/; |
214
|
|
|
|
|
|
|
} else { |
215
|
0
|
|
|
|
|
|
$public_id =~ s/_DET_/2/; |
216
|
0
|
|
|
|
|
|
$system_id =~ s/_DET_/2/; |
217
|
|
|
|
|
|
|
} |
218
|
0
|
|
|
|
|
|
$self->start_dtd( { |
219
|
|
|
|
|
|
|
Name => 'dirtree', |
220
|
|
|
|
|
|
|
PublicId => $public_id, |
221
|
|
|
|
|
|
|
SystemId => $system_id, |
222
|
|
|
|
|
|
|
} ); |
223
|
0
|
|
|
|
|
|
$self->end_dtd; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__ |