line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
2
|
|
|
|
|
|
|
package XML::NodeFilter; |
3
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
4
|
|
|
|
|
|
|
# $Id: NodeFilter.pm,v 1.1.1.1 2002/11/08 09:26:59 phish108 Exp $ |
5
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
6
|
|
|
|
|
|
|
# (c) 2002 Christian Glahn # |
7
|
|
|
|
|
|
|
# All rights reserved. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# This code is free software; you can redistribute it and/or # |
10
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. # |
11
|
|
|
|
|
|
|
# # |
12
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
15
|
|
|
|
|
|
|
# general settings # |
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
17
|
1
|
|
|
1
|
|
6302
|
use 5.005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
18
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Exporter; |
21
|
1
|
|
|
|
|
236
|
use vars qw( $VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK |
22
|
1
|
|
|
1
|
|
5
|
@FLAGNAMES %FLAGMAPPING); |
|
1
|
|
|
|
|
6
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = '0.01'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
30
|
|
|
|
|
|
|
# export information # |
31
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
34
|
|
|
|
|
|
|
'results' => [ qw( |
35
|
|
|
|
|
|
|
FILTER_DECLINED |
36
|
|
|
|
|
|
|
FILTER_ACCEPT |
37
|
|
|
|
|
|
|
FILTER_SKIP |
38
|
|
|
|
|
|
|
FILTER_REJECT |
39
|
|
|
|
|
|
|
) ], |
40
|
|
|
|
|
|
|
'flags' => [ qw( |
41
|
|
|
|
|
|
|
SHOW_ALL |
42
|
|
|
|
|
|
|
SHOW_ELEMENT |
43
|
|
|
|
|
|
|
SHOW_ATTRIBUTE |
44
|
|
|
|
|
|
|
SHOW_TEXT |
45
|
|
|
|
|
|
|
SHOW_CDATA_SECTION |
46
|
|
|
|
|
|
|
SHOW_ENTITY_REFERENCE |
47
|
|
|
|
|
|
|
SHOW_ENTITY |
48
|
|
|
|
|
|
|
SHOW_PROCESSING_INSTRUCTION |
49
|
|
|
|
|
|
|
SHOW_COMMENT |
50
|
|
|
|
|
|
|
SHOW_DOCUMENT |
51
|
|
|
|
|
|
|
SHOW_DOCUMENT_TYPE |
52
|
|
|
|
|
|
|
SHOW_DOCUMENT_FRAGMENT |
53
|
|
|
|
|
|
|
SHOW_NOTATION |
54
|
|
|
|
|
|
|
SHOW_NONE |
55
|
|
|
|
|
|
|
) ], |
56
|
|
|
|
|
|
|
'all' => [ qw( |
57
|
|
|
|
|
|
|
FILTER_DECLINED |
58
|
|
|
|
|
|
|
FILTER_ACCEPT |
59
|
|
|
|
|
|
|
FILTER_SKIP |
60
|
|
|
|
|
|
|
FILTER_REJECT |
61
|
|
|
|
|
|
|
SHOW_ALL |
62
|
|
|
|
|
|
|
SHOW_ELEMENT |
63
|
|
|
|
|
|
|
SHOW_ATTRIBUTE |
64
|
|
|
|
|
|
|
SHOW_TEXT |
65
|
|
|
|
|
|
|
SHOW_CDATA_SECTION |
66
|
|
|
|
|
|
|
SHOW_ENTITY_REFERENCE |
67
|
|
|
|
|
|
|
SHOW_ENTITY |
68
|
|
|
|
|
|
|
SHOW_PROCESSING_INSTRUCTION |
69
|
|
|
|
|
|
|
SHOW_COMMENT |
70
|
|
|
|
|
|
|
SHOW_DOCUMENT |
71
|
|
|
|
|
|
|
SHOW_DOCUMENT_TYPE |
72
|
|
|
|
|
|
|
SHOW_DOCUMENT_FRAGMENT |
73
|
|
|
|
|
|
|
SHOW_NOTATION |
74
|
|
|
|
|
|
|
SHOW_NONE |
75
|
|
|
|
|
|
|
) ] ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
@EXPORT = qw(); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
82
|
|
|
|
|
|
|
# constants declaration # |
83
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
@FLAGNAMES = qw( |
86
|
|
|
|
|
|
|
SHOW_ELEMENT |
87
|
|
|
|
|
|
|
SHOW_ATTRIBUTE |
88
|
|
|
|
|
|
|
SHOW_TEXT |
89
|
|
|
|
|
|
|
SHOW_CDATA_SECTION |
90
|
|
|
|
|
|
|
SHOW_ENTITY_REFERENCE |
91
|
|
|
|
|
|
|
SHOW_ENTITY |
92
|
|
|
|
|
|
|
SHOW_PROCESSING_INSTRUCTION |
93
|
|
|
|
|
|
|
SHOW_COMMENT |
94
|
|
|
|
|
|
|
SHOW_DOCUMENT |
95
|
|
|
|
|
|
|
SHOW_DOCUMENT_TYPE |
96
|
|
|
|
|
|
|
SHOW_DOCUMENT_FRAGMENT |
97
|
|
|
|
|
|
|
SHOW_NOTATION |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
1
|
|
5
|
use constant FILTER_DECLINED => 0; # check what other filters say ... |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
101
|
1
|
|
|
1
|
|
4
|
use constant FILTER_ACCEPT => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
102
|
1
|
|
|
1
|
|
5
|
use constant FILTER_SKIP => 2; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
103
|
1
|
|
|
1
|
|
4
|
use constant FILTER_REJECT => 3; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
1
|
|
4
|
use constant SHOW_ALL => 0xFFFFFFFF; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
106
|
1
|
|
|
1
|
|
4
|
use constant SHOW_ELEMENT => 0x00000001; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
32
|
|
107
|
1
|
|
|
1
|
|
4
|
use constant SHOW_ATTRIBUTE => 0x00000002; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
108
|
1
|
|
|
1
|
|
3
|
use constant SHOW_TEXT => 0x00000004; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
109
|
1
|
|
|
1
|
|
4
|
use constant SHOW_CDATA_SECTION => 0x00000008; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
110
|
1
|
|
|
1
|
|
4
|
use constant SHOW_ENTITY_REFERENCE => 0x00000010; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
111
|
1
|
|
|
1
|
|
9
|
use constant SHOW_ENTITY => 0x00000020; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
112
|
1
|
|
|
1
|
|
4
|
use constant SHOW_PROCESSING_INSTRUCTION => 0x00000040; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
113
|
1
|
|
|
1
|
|
4
|
use constant SHOW_COMMENT => 0x00000080; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
114
|
1
|
|
|
1
|
|
4
|
use constant SHOW_DOCUMENT => 0x00000100; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
115
|
1
|
|
|
1
|
|
3
|
use constant SHOW_DOCUMENT_TYPE => 0x00000200; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
116
|
1
|
|
|
1
|
|
12
|
use constant SHOW_DOCUMENT_FRAGMENT => 0x00000400; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
117
|
1
|
|
|
1
|
|
4
|
use constant SHOW_NOTATION => 0x00000800; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# why are specs always incomplete regarding the NULL set??? |
120
|
1
|
|
|
1
|
|
5
|
use constant SHOW_NONE => 0x00000000; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
616
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
@FLAGMAPPING{@FLAGNAMES} = (SHOW_ELEMENT, |
123
|
|
|
|
|
|
|
SHOW_ATTRIBUTE, |
124
|
|
|
|
|
|
|
SHOW_TEXT, |
125
|
|
|
|
|
|
|
SHOW_CDATA_SECTION, |
126
|
|
|
|
|
|
|
SHOW_ENTITY_REFERENCE, |
127
|
|
|
|
|
|
|
SHOW_ENTITY, |
128
|
|
|
|
|
|
|
SHOW_PROCESSING_INSTRUCTION, |
129
|
|
|
|
|
|
|
SHOW_COMMENT, |
130
|
|
|
|
|
|
|
SHOW_DOCUMENT, |
131
|
|
|
|
|
|
|
SHOW_DOCUMENT_TYPE, |
132
|
|
|
|
|
|
|
SHOW_DOCUMENT_FRAGMENT, |
133
|
|
|
|
|
|
|
SHOW_NOTATION); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
136
|
|
|
|
|
|
|
# class constructor # |
137
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
138
|
|
|
|
|
|
|
sub new { |
139
|
3
|
|
|
3
|
1
|
82
|
my $class = shift; |
140
|
3
|
|
|
|
|
8
|
my %args = @_; |
141
|
3
|
|
|
|
|
3
|
my $flags = SHOW_ALL; |
142
|
3
|
50
|
|
|
|
16
|
if ( defined $args{WHAT_TO_SHOW} ) { |
|
|
100
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
$flags = $args{WHAT_TO_SHOW}; |
144
|
0
|
|
|
|
|
0
|
delete $args{WHAT_TO_SHOW}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ( defined $args{-show} ) { |
147
|
2
|
|
|
|
|
4
|
$flags = $args{-show}; |
148
|
2
|
|
|
|
|
5
|
delete $args{-show}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
3
|
|
|
|
|
8
|
my $self = bless \%args, $class; |
152
|
|
|
|
|
|
|
|
153
|
3
|
100
|
|
|
|
11
|
$self->what_to_show( ref( $flags ) ? %{$flags} : $flags ); |
|
1
|
|
|
|
|
4
|
|
154
|
|
|
|
|
|
|
|
155
|
3
|
|
|
|
|
7
|
return $self; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
159
|
|
|
|
|
|
|
# what_to_show # |
160
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
161
|
|
|
|
|
|
|
sub what_to_show { |
162
|
19
|
|
|
19
|
1
|
597
|
my $self = shift; |
163
|
19
|
|
|
|
|
31
|
my $mask = $self->{WHAT_TO_SHOW}; |
164
|
|
|
|
|
|
|
|
165
|
19
|
100
|
|
|
|
35
|
if ( my $n = scalar @_ ) { |
166
|
8
|
100
|
|
|
|
17
|
if ( $n == 1) { |
|
|
50
|
|
|
|
|
|
167
|
6
|
|
|
|
|
7
|
$mask = shift; |
168
|
6
|
100
|
|
|
|
13
|
unless ( defined $mask ) { |
169
|
1
|
|
|
|
|
2
|
$self->{WHAT_TO_SHOW} = SHOW_ALL; |
170
|
1
|
|
|
|
|
2
|
$mask = SHOW_ALL; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
elsif ( $n > 1 ) { |
174
|
2
|
|
|
|
|
5
|
my %args = @_; |
175
|
2
|
|
|
|
|
3
|
$mask= SHOW_NONE; |
176
|
|
|
|
|
|
|
|
177
|
2
|
|
|
|
|
4
|
foreach ( keys %args ) { |
178
|
4
|
50
|
33
|
|
|
32
|
if ( defined $FLAGMAPPING{$_} |
|
|
|
33
|
|
|
|
|
179
|
|
|
|
|
|
|
and defined $args{$_} |
180
|
|
|
|
|
|
|
and $args{$_} ){ |
181
|
4
|
|
|
|
|
8
|
$mask |= $FLAGMAPPING{$_}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
2
|
50
|
|
|
|
7
|
if ( defined $args{SHOW_ALL} ) { |
186
|
0
|
|
|
|
|
0
|
$mask = SHOW_ALL; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
8
|
|
|
|
|
11
|
$self->{WHAT_TO_SHOW} = $mask; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
19
|
100
|
|
|
|
29
|
if ( wantarray ) { |
195
|
4
|
|
|
|
|
6
|
my %retval = (); |
196
|
|
|
|
|
|
|
|
197
|
4
|
100
|
|
|
|
6
|
@retval{@FLAGNAMES} = map { $mask & $_ ? "1" : "0" } ( |
|
48
|
|
|
|
|
110
|
|
198
|
|
|
|
|
|
|
SHOW_ELEMENT, |
199
|
|
|
|
|
|
|
SHOW_ATTRIBUTE, |
200
|
|
|
|
|
|
|
SHOW_TEXT, |
201
|
|
|
|
|
|
|
SHOW_CDATA_SECTION, |
202
|
|
|
|
|
|
|
SHOW_ENTITY_REFERENCE, |
203
|
|
|
|
|
|
|
SHOW_ENTITY, |
204
|
|
|
|
|
|
|
SHOW_PROCESSING_INSTRUCTION, |
205
|
|
|
|
|
|
|
SHOW_COMMENT, |
206
|
|
|
|
|
|
|
SHOW_DOCUMENT, |
207
|
|
|
|
|
|
|
SHOW_DOCUMENT_TYPE, |
208
|
|
|
|
|
|
|
SHOW_DOCUMENT_FRAGMENT, |
209
|
|
|
|
|
|
|
SHOW_NOTATION |
210
|
|
|
|
|
|
|
); |
211
|
4
|
|
|
|
|
45
|
return %retval; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
15
|
|
|
|
|
36
|
return $mask; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
218
|
|
|
|
|
|
|
# accept_node and acceptNode # |
219
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
220
|
|
|
|
|
|
|
# accept_node() will call acceptNode() on default. This allows a # |
221
|
|
|
|
|
|
|
# transparent implementation towards spec conformance. # |
222
|
|
|
|
|
|
|
# # |
223
|
|
|
|
|
|
|
# the default return value is FILTER_ACCEPT rather than FILTER_DECLINED, # |
224
|
|
|
|
|
|
|
# because FILTER_DECLINED was not specified # |
225
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
226
|
1
|
|
|
1
|
1
|
37
|
sub accept_node { my $s = shift; return $s->acceptNode( @_ ); } |
|
1
|
|
|
|
|
3
|
|
227
|
2
|
|
|
2
|
1
|
9
|
sub acceptNode { return FILTER_ACCEPT; } |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; |
230
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
231
|
|
|
|
|
|
|
# Code End # |
232
|
|
|
|
|
|
|
#------------------------------------------------------------------------# |
233
|
|
|
|
|
|
|
__END__ |