| 1 | package XML::LibXML::Cache; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 1 | $XML::LibXML::Cache::VERSION = '0.12'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | # ABSTRACT: Document cache for XML::LibXML | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use base qw(XML::LibXML::Cache::Base); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use XML::LibXML 1.59; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||
| 14 | 1 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||
| 15 | 1 | ▶ | my $options = @_ > 1 ? { @_ } : $_[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | my $self = $class->SUPER::new; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | my $parser = $options->{parser} || XML::LibXML->new; | ||||||||||||||||||
|
Condition33%1/3
$options->{'parser'} || 'XML::LibXML'->new
MC/DC0%0/2
$options->{'parser'} || 'XML::LibXML'->new
$options->{'parser'}
'XML::LibXML'->new
Truth table33%1/3
A || B
A= $options->{'parser'}B= 'XML::LibXML'->new
| |||||||||||||||||||||
| 20 | 1 | $self->{parser} = $parser; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 1 | $parser->input_callbacks($XML::LibXML::Cache::Base::input_callbacks); | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | return $self; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub parse_file { | ||||||||||||||||||||
| 28 | 3 | ▶ | my ($self, $filename) = @_; | ||||||||||||||||||
|
Subroutine
parse_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | return $self->_cache_lookup($filename, sub { | ||||||||||||||||||||
| 31 | 1 | ▶ | my $filename = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | return $self->{parser}->parse_file($filename); | |||||||||||||||||||
| 34 | 3 | }); | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | sub parse_html_file { | ||||||||||||||||||||
| 38 | 0 | ▶ | my ($self, $filename, @args) = @_; | ||||||||||||||||||
|
Subroutine
parse_html_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | return $self->_cache_lookup($filename, sub { | ||||||||||||||||||||
| 41 | 0 | ▶ | my $filename = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | return $self->{parser}->parse_html_file($filename, @args); | |||||||||||||||||||
| 44 | 0 | }); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | 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<XML::LibXML> 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<XML::LibXML> 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<XML::LibXML::Parser/parse_file>. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head2 parse_html_file | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | my $doc = $cache->parse_html_file($filename, \%opts); | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | Works like L<XML::LibXML::Parser/parse_html_file>. | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head1 AUTHOR | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | Nick Wellnhofer <wellnhofer@aevum.de> | ||||||||||||||||||||
| 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__ | ||||||||||||||||||||