line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package XML::SAX::ParserFactory; |
4
|
|
|
|
|
|
|
|
5
|
15
|
|
|
15
|
|
4373
|
use strict; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
405
|
|
6
|
15
|
|
|
15
|
|
75
|
use vars qw($VERSION); |
|
15
|
|
|
|
|
22
|
|
|
15
|
|
|
|
|
622
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '1.02'; |
9
|
|
|
|
|
|
|
|
10
|
15
|
|
|
15
|
|
433
|
use Symbol qw(gensym); |
|
15
|
|
|
|
|
650
|
|
|
15
|
|
|
|
|
580
|
|
11
|
15
|
|
|
15
|
|
426
|
use XML::SAX; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
377
|
|
12
|
15
|
|
|
15
|
|
1531
|
use XML::SAX::Exception; |
|
15
|
|
|
|
|
9759
|
|
|
15
|
|
|
|
|
8655
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
10
|
|
|
10
|
0
|
342
|
my $class = shift; |
16
|
10
|
|
|
|
|
15
|
my %params = @_; # TODO : Fix this in spec. |
17
|
10
|
|
|
|
|
21
|
my $self = bless \%params, $class; |
18
|
10
|
|
|
|
|
30
|
$self->{KnownParsers} = XML::SAX->parsers(); |
19
|
10
|
|
|
|
|
26
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub parser { |
23
|
12
|
|
|
12
|
0
|
528
|
my $self = shift; |
24
|
12
|
|
|
|
|
58
|
my @parser_params = @_; |
25
|
12
|
100
|
|
|
|
25
|
if (!ref($self)) { |
26
|
8
|
|
|
|
|
19
|
$self = $self->new(); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
12
|
|
|
|
|
23
|
my $parser_class = $self->_parser_class(); |
30
|
|
|
|
|
|
|
|
31
|
11
|
|
|
|
|
19
|
my $version = ''; |
32
|
11
|
100
|
|
|
|
36
|
if ($parser_class =~ s/\s*\(([\d\.]+)\)\s*$//) { |
33
|
1
|
|
|
|
|
3
|
$version = " $1"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
11
|
100
|
|
|
|
78
|
if (!$parser_class->can('new')) { |
37
|
1
|
|
|
|
|
58
|
eval "require $parser_class $version;"; |
38
|
1
|
50
|
|
|
|
95
|
die $@ if $@; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
11
|
|
|
|
|
34
|
return $parser_class->new(@parser_params); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub require_feature { |
45
|
2
|
|
|
2
|
0
|
175
|
my $self = shift; |
46
|
2
|
|
|
|
|
6
|
my ($feature) = @_; |
47
|
2
|
|
|
|
|
5
|
$self->{RequiredFeatures}{$feature}++; |
48
|
2
|
|
|
|
|
7
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _parser_class { |
52
|
12
|
|
|
12
|
|
19
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# First try ParserPackage |
55
|
12
|
100
|
|
|
|
19
|
if ($XML::SAX::ParserPackage) { |
56
|
2
|
|
|
|
|
5
|
return $XML::SAX::ParserPackage; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Now check if required/preferred is there |
60
|
10
|
100
|
|
|
|
21
|
if ($self->{RequiredFeatures}) { |
61
|
2
|
|
|
|
|
4
|
my %required = %{$self->{RequiredFeatures}}; |
|
2
|
|
|
|
|
7
|
|
62
|
|
|
|
|
|
|
# note - we never go onto the next try (ParserDetails.ini), |
63
|
|
|
|
|
|
|
# because if we can't provide the requested feature |
64
|
|
|
|
|
|
|
# we need to throw an exception. |
65
|
|
|
|
|
|
|
PARSER: |
66
|
2
|
|
|
|
|
3
|
foreach my $parser (reverse @{$self->{KnownParsers}}) { |
|
2
|
|
|
|
|
4
|
|
67
|
2
|
|
|
|
|
4
|
foreach my $feature (keys %required) { |
68
|
2
|
100
|
|
|
|
6
|
if (!exists $parser->{Features}{$feature}) { |
69
|
1
|
|
|
|
|
4
|
next PARSER; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
# got here - all features must exist! |
73
|
1
|
|
|
|
|
3
|
return $parser->{Name}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
# TODO : should this be NotSupported() ? |
76
|
|
|
|
|
|
|
throw XML::SAX::Exception ( |
77
|
1
|
|
|
|
|
7
|
Message => "Unable to provide required features", |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Next try SAX.ini |
82
|
8
|
|
|
|
|
17
|
for my $dir (@INC) { |
83
|
93
|
|
|
|
|
227
|
my $fh = gensym(); |
84
|
93
|
100
|
|
|
|
1893
|
if (open($fh, "$dir/SAX.ini")) { |
85
|
5
|
|
|
|
|
27
|
my $param_list = XML::SAX->_parse_ini_file($fh); |
86
|
5
|
|
|
|
|
9
|
my $params = $param_list->[0]->{Features}; |
87
|
5
|
100
|
|
|
|
10
|
if ($params->{ParserPackage}) { |
88
|
2
|
|
|
|
|
23
|
return $params->{ParserPackage}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
|
|
|
|
|
|
# we have required features (or nothing?) |
92
|
|
|
|
|
|
|
PARSER: |
93
|
3
|
|
|
|
|
5
|
foreach my $parser (reverse @{$self->{KnownParsers}}) { |
|
3
|
|
|
|
|
6
|
|
94
|
4
|
|
|
|
|
11
|
foreach my $feature (keys %$params) { |
95
|
4
|
100
|
|
|
|
11
|
if (!exists $parser->{Features}{$feature}) { |
96
|
2
|
|
|
|
|
5
|
next PARSER; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
2
|
|
|
|
|
25
|
return $parser->{Name}; |
100
|
|
|
|
|
|
|
} |
101
|
1
|
|
|
|
|
5
|
XML::SAX->do_warn("Unable to provide SAX.ini required features. Using fallback\n"); |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
11
|
last; # stop after first INI found |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
4
|
50
|
|
|
|
10
|
if (@{$self->{KnownParsers}}) { |
|
4
|
|
|
|
|
15
|
|
108
|
4
|
|
|
|
|
13
|
return $self->{KnownParsers}[-1]{Name}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
0
|
|
|
|
|
|
return "XML::SAX::PurePerl"; # backup plan! |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
__END__ |