line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::LibXML::Cache; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$XML::LibXML::Cache::VERSION = '0.12'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
770
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Document cache for XML::LibXML |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use base qw(XML::LibXML::Cache::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
631
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use XML::LibXML 1.59; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
my $options = @_ > 1 ? { @_ } : $_[0]; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = $class->SUPER::new; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $parser = $options->{parser} || XML::LibXML->new; |
20
|
|
|
|
|
|
|
$self->{parser} = $parser; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$parser->input_callbacks($XML::LibXML::Cache::Base::input_callbacks); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub parse_file { |
28
|
|
|
|
|
|
|
my ($self, $filename) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
return $self->_cache_lookup($filename, sub { |
31
|
|
|
|
|
|
|
my $filename = shift; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return $self->{parser}->parse_file($filename); |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub parse_html_file { |
38
|
|
|
|
|
|
|
my ($self, $filename, @args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $self->_cache_lookup($filename, sub { |
41
|
|
|
|
|
|
|
my $filename = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return $self->{parser}->parse_html_file($filename, @args); |
44
|
|
|
|
|
|
|
}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
XML::LibXML::Cache - Document cache for XML::LibXML |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 0.12 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $cache = XML::LibXML::Cache->new; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $doc = $cache->parse_file('file.xml'); |
66
|
|
|
|
|
|
|
my $doc = $cache->parse_html_file('file.html', \%opts); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 DESCRIPTION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
XML::LibXML::Cache is a cache for L documents loaded from |
71
|
|
|
|
|
|
|
files. It is useful to speed up loading of XML files in persistent web |
72
|
|
|
|
|
|
|
applications. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This module caches the document object after the first load and returns the |
75
|
|
|
|
|
|
|
cached version on subsequent loads. Documents are reloaded whenever the |
76
|
|
|
|
|
|
|
document file changes. Changes to other files referenced during parsing also |
77
|
|
|
|
|
|
|
cause a reload. This includes external DTDs, external entities or XIncludes. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 new |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $cache = XML::LibXML::Cache->new(%opts); |
84
|
|
|
|
|
|
|
my $cache = XML::LibXML::Cache->new(\%opts); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Creates a new cache. Valid options are: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item parser |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The L parser object that should be used to load documents if you |
93
|
|
|
|
|
|
|
want to use certain parser options. If this options is missing a parser |
94
|
|
|
|
|
|
|
with default options will be used. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 parse_file |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $doc = $cache->parse_file($filename); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Works like L. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 parse_html_file |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $doc = $cache->parse_html_file($filename, \%opts); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Works like L. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Nick Wellnhofer |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Nick Wellnhofer. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
119
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |