line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Cache.pm,v 1.3 2002/01/30 12:33:21 matt Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package XML::Filter::Cache; |
4
|
4
|
|
|
4
|
|
39538
|
use strict; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
242
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
22
|
use vars qw($VERSION $AUTOLOAD @ISA); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
326
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
6115
|
use XML::SAX::Base; |
|
4
|
|
|
|
|
125071
|
|
|
4
|
|
|
|
|
220
|
|
11
|
|
|
|
|
|
|
@ISA = qw(XML::SAX::Base); |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
160886
|
use Storable (); |
|
4
|
|
|
|
|
19490
|
|
|
4
|
|
|
|
|
322
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
3
|
|
|
3
|
0
|
723
|
my $class = shift; |
17
|
3
|
50
|
|
|
|
30
|
my $opts = (@_ == 1) ? { %{shift(@_)} } : {@_}; |
|
0
|
|
|
|
|
0
|
|
18
|
|
|
|
|
|
|
|
19
|
3
|
|
50
|
|
|
27
|
$opts->{Class} ||= 'File'; |
20
|
|
|
|
|
|
|
{ |
21
|
4
|
|
|
4
|
|
40
|
no strict 'refs'; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
2376
|
|
|
3
|
|
|
|
|
5
|
|
22
|
3
|
|
|
|
|
224
|
eval "require XML::Filter::Cache::$opts->{Class};" |
23
|
3
|
50
|
|
|
|
5
|
unless ${"XML::Filter::Cache::".$opts->{Class}."::VERSION"}; |
24
|
3
|
50
|
|
|
|
20
|
if ($@) { |
25
|
0
|
|
|
|
|
0
|
die $@; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
27
|
return "XML::Filter::Cache::$opts->{Class}"->new($opts); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub playback { |
33
|
2
|
|
|
2
|
0
|
23917
|
my $self = shift; |
34
|
2
|
|
|
|
|
11
|
$self->open("r"); |
35
|
2
|
|
|
|
|
9
|
while (my $record = $self->_read) { |
36
|
1345
|
|
|
|
|
3059
|
my $thawed = Storable::thaw($record); |
37
|
1345
|
|
|
|
|
20444
|
$self->_playback($thawed); |
38
|
|
|
|
|
|
|
} |
39
|
2
|
|
|
|
|
10
|
$self->close; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _playback { |
43
|
1345
|
|
|
1345
|
|
1820
|
my ($self, $thawed) = @_; |
44
|
1345
|
|
|
|
|
1858
|
my ($method, $structure) = @$thawed; |
45
|
1345
|
|
|
|
|
1893
|
my $supermethod = "SUPER::$method"; |
46
|
1345
|
|
|
|
|
4384
|
$self->$supermethod($structure); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub record { |
50
|
1345
|
|
|
1345
|
0
|
2376
|
my ($self, $event, $structure) = @_; |
51
|
1345
|
|
|
|
|
4260
|
my $frozen = Storable::nfreeze([$event, $structure]); |
52
|
1345
|
|
|
|
|
39750
|
$self->_write($frozen); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _read { |
56
|
0
|
|
|
0
|
|
0
|
die "Abstract base method _read called"; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _write { |
60
|
0
|
|
|
0
|
|
0
|
die "Abstract base method _write called"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my @sax_events = qw( |
64
|
|
|
|
|
|
|
start_element |
65
|
|
|
|
|
|
|
end_element |
66
|
|
|
|
|
|
|
characters |
67
|
|
|
|
|
|
|
processing_instruction |
68
|
|
|
|
|
|
|
ignorable_whitespace |
69
|
|
|
|
|
|
|
start_prefix_mapping |
70
|
|
|
|
|
|
|
end_prefix_mapping |
71
|
|
|
|
|
|
|
start_cdata |
72
|
|
|
|
|
|
|
end_cdata |
73
|
|
|
|
|
|
|
skipped_entity |
74
|
|
|
|
|
|
|
notation_decl |
75
|
|
|
|
|
|
|
unparsed_entity_decl |
76
|
|
|
|
|
|
|
element_decl |
77
|
|
|
|
|
|
|
attribute_decl |
78
|
|
|
|
|
|
|
internal_entity_decl |
79
|
|
|
|
|
|
|
external_entity_decl |
80
|
|
|
|
|
|
|
comment |
81
|
|
|
|
|
|
|
start_dtd |
82
|
|
|
|
|
|
|
end_dtd |
83
|
|
|
|
|
|
|
start_entity |
84
|
|
|
|
|
|
|
end_entity |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $methods = ''; |
88
|
|
|
|
|
|
|
foreach my $method (@sax_events) { |
89
|
|
|
|
|
|
|
$methods .= <
|
90
|
|
|
|
|
|
|
sub $method { |
91
|
|
|
|
|
|
|
my (\$self, \$param) = \@_; |
92
|
|
|
|
|
|
|
\$self->record($method => \$param); |
93
|
|
|
|
|
|
|
return \$self->SUPER::$method(\$param); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
EOT |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
0
|
1
|
0
|
eval $methods; |
|
0
|
|
|
692
|
1
|
0
|
|
|
0
|
|
|
1
|
1
|
0
|
|
|
692
|
|
|
0
|
1
|
127866
|
|
|
692
|
|
|
0
|
1
|
2113
|
|
|
692
|
|
|
0
|
1
|
2360
|
|
|
1
|
|
|
323
|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
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
98
|
|
|
|
|
|
|
if ($@) { |
99
|
|
|
|
|
|
|
die $@; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Only some parsers call set_document_locator, and it's called before |
103
|
|
|
|
|
|
|
# start_document. So we keep it in $self, and open the cache in start_document, |
104
|
|
|
|
|
|
|
# then write out the set_document_locator event |
105
|
|
|
|
|
|
|
sub set_document_locator { |
106
|
2
|
|
|
2
|
1
|
172633
|
my ($self, $locator) = @_; |
107
|
2
|
|
|
|
|
19
|
$self->{_locator} = $locator; |
108
|
2
|
|
|
|
|
48
|
$self->SUPER::set_document_locator($locator); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub start_document { |
112
|
2
|
|
|
2
|
1
|
222
|
my ($self, $doc) = @_; |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
50
|
|
|
19
|
local $self->{Key} = $self->{Key} || $self->{_locator}{SystemId} || die "No cache Key supplied"; |
115
|
2
|
|
|
|
|
15
|
$self->open("w"); |
116
|
2
|
50
|
|
|
|
20
|
if (my $locator = delete $self->{_locator}) { |
117
|
2
|
|
|
|
|
16
|
$self->record(set_document_locator => { %$locator }); |
118
|
|
|
|
|
|
|
} |
119
|
2
|
|
|
|
|
16
|
$self->record(start_document => $doc); |
120
|
2
|
|
|
|
|
134
|
$self->SUPER::start_document($doc); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub end_document { |
124
|
2
|
|
|
2
|
1
|
544
|
my ($self, $doc) = @_; |
125
|
2
|
|
|
|
|
9
|
$self->record(end_document => $doc); |
126
|
2
|
|
|
|
|
9
|
$self->close(); |
127
|
2
|
|
|
|
|
28
|
$self->SUPER::end_document($doc); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
__END__ |