line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Filter::Namespace; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22911
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base qw( XML::SAX::Base Class::Accessor ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1462
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
28062
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
886
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Manually maintained, this is the package's version number. |
10
|
|
|
|
|
|
|
$VERSION = '1.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub start_document { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
14
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
die __PACKAGE__.": no namespace specified\n" |
17
|
|
|
|
|
|
|
unless $self->ns; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$self->seen_root( 0 ); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if ($self->nl_after_tag) { |
22
|
0
|
0
|
|
|
|
|
die __PACKAGE__.": nl_after_tag: not a hash ref\n" |
23
|
|
|
|
|
|
|
unless ref($self->nl_after_tag) eq 'HASH'; |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
|
$self->nl_after_tag( {} ); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$self->SUPER::start_document( $data ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Stub out these as we provide our own. |
32
|
0
|
|
|
0
|
1
|
|
sub start_dtd { } |
33
|
0
|
|
|
0
|
1
|
|
sub end_dtd { } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Destroy comments. |
36
|
0
|
|
|
0
|
1
|
|
sub comment { } |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub wanted_ns { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
41
|
0
|
|
0
|
|
|
|
return $data->{ NamespaceURI } && $data->{ NamespaceURI } eq $self->ns; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my $in_ns = 0; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub start_prefix_mapping { |
48
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
return unless $self->wanted_ns( $data ); |
52
|
0
|
0
|
|
|
|
|
return if $in_ns++; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Make it the default namespace. |
55
|
0
|
|
|
|
|
|
$data->{ Prefix } = ''; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->SUPER::start_prefix_mapping( $data ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub end_prefix_mapping { |
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
return unless $self->wanted_ns( $data ); |
65
|
0
|
0
|
|
|
|
|
return unless $in_ns--; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->SUPER::end_prefix_mapping( $data ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub start_element { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
return unless $self->wanted_ns( $data ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Delete each attribute that isn't in our namespace. |
78
|
0
|
|
|
|
|
|
foreach my $att_name ( keys %{ $data->{ Attributes } } ) { |
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $attr = $data->{ Attributes }->{ $att_name }; |
80
|
0
|
0
|
|
|
|
|
next if $self->wanted_ns( $attr ); |
81
|
0
|
|
|
|
|
|
delete $data->{ Attributes }->{ $att_name }; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->fix_attr_prefix( $data->{ Attributes } ); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
|
$self->emit_doctype( $data ) |
|
|
|
0
|
|
|
|
|
87
|
|
|
|
|
|
|
if !$self->seen_root && ($self->systemid || $self->publicid); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->SUPER::start_element( $data ); |
90
|
0
|
|
|
|
|
|
$self->seen_root( 1 ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub emit_doctype { |
94
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
95
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
0
|
|
|
|
warn __PACKAGE__.": public id specified with no system id\n" |
98
|
|
|
|
|
|
|
if $self->publicid && ! $self->systemid; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$self->SUPER::start_dtd( { |
101
|
|
|
|
|
|
|
Name => $data->{ LocalName }, |
102
|
0
|
|
0
|
|
|
|
SystemId => $self->systemid || '', |
|
|
|
0
|
|
|
|
|
103
|
|
|
|
|
|
|
PublicId => $self->publicid || '', |
104
|
|
|
|
|
|
|
} ); |
105
|
0
|
|
|
|
|
|
$self->SUPER::end_dtd( {} ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub end_element { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
my ( $data ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
return unless $self->wanted_ns( $data ); |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$self->SUPER::end_element( $data ); |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
$self->characters( { Data => "\n" } ) |
117
|
|
|
|
|
|
|
if $self->nl_after_tag->{ $data->{LocalName} }; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub fix_attr_prefix { |
121
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
my ( $attrs ) = @_; |
123
|
0
|
|
|
|
|
|
foreach my $a ( values %$attrs ) { |
124
|
0
|
|
|
|
|
|
$a->{ Name } =~ s/.*://; |
125
|
0
|
|
|
|
|
|
$a->{ Prefix } = ''; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw( ns systemid publicid seen_root nl_after_tag ) ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
__END__ |