LibXSLT/Cache.pm

filter: Statementstmt 65.2% 15 / 23 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 64.7% 22 / 34 SCAR 12.4
CC
3
Cov
63%
new
3.7
parse_stylesheet_file
2.0
__ANON__
2.0
CRAP 3.5
« LibXML/Cache/Base.pm ↑ Summary LibXML/Cache.pm »
1 package XML::LibXSLT::Cache;
2 {
3 1 $XML::LibXSLT::Cache::VERSION = '0.12';
4 }
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: Style sheet cache for XML::LibXSLT
8  
9 1 ▶use base qw(XML::LibXML::Cache::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new {
12 1 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=13.1
Pod documented
13 1 ▶ my $options = @_ > 1 ? { @_ } : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 1 1
14  
15 1 my $self = $class->SUPER::new;
16  
17 1 my $xslt = $options->{xslt};
18
19 1 ▶ if (!$xslt) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xslt) 1 0 1
20 1 require XML::LibXSLT;
21 0 $xslt = XML::LibXSLT->new;
22 }
23  
24 0 $self->{xslt} = $xslt;
25  
26 0 $xslt->input_callbacks($XML::LibXML::Cache::Base::input_callbacks);
27  
28 0 return $self;
29 }
30  
31 sub parse_stylesheet_file {
32 0 ▶ my ($self, $filename) = @_;
Subroutine parse_stylesheet_file: not called CC=1 SCAR=6.9
Pod documented
33  
34 return $self->_cache_lookup($filename, sub {
35 0 ▶ my $filename = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
36  
37 0 return $self->{xslt}->parse_stylesheet_file($filename);
38 0 });
39 }
40  
41 1 1;
42  
43  
44  
45 =pod
46  
47 =head1 NAME
48  
49 XML::LibXSLT::Cache - Style sheet cache for XML::LibXSLT
50  
51 =head1 VERSION
52  
53 version 0.12
54  
55 =head1 SYNOPSIS
56  
57 my $cache = XML::LibXSLT::Cache->new;
58  
59 my $stylesheet = $cache->parse_stylesheet_file('file.xsl');
60  
61 =head1 DESCRIPTION
62  
63 XML::LibXSLT::Cache is a cache for L<XML::LibXSLT> style sheets loaded from
64 files. It is useful to speed up loading of XSLT style sheets in persistent web
65 applications.
66  
67 This module caches the style sheet object after the first load and returns the
68 cached version on subsequent loads. Style sheets are reloaded whenever the
69 style sheet file changes. Changes to other files referenced during parsing also
70 cause a reload, for example when using xsl:import and xsl:include.
71  
72 =head1 METHODS
73  
74 =head2 new
75  
76 my $cache = XML::LibXSLT::Cache->new(%opts);
77 my $cache = XML::LibXSLT::Cache->new(\%opts);
78  
79 Creates a new cache. Valid options are:
80  
81 =over
82  
83 =item xslt
84  
85 The L<XML::LibXSLT> object that should be used to load stylsheets if you
86 want to reuse an existing object. If this options is missing a new
87 XML::LibXSLT object will be created.
88  
89 =back
90  
91 =head2 parse_stylesheet_file
92  
93 my $stylesheet = $cache->parse_stylesheet_file($filename);
94  
95 Works like L<XML::LibXSLT/parse_stylesheet_file>.
96  
97 =head1 AUTHOR
98  
99 Nick Wellnhofer <wellnhofer@aevum.de>
100  
101 =head1 COPYRIGHT AND LICENSE
102  
103 This software is copyright (c) 2012 by Nick Wellnhofer.
104  
105 This is free software; you can redistribute it and/or modify it under
106 the same terms as the Perl 5 programming language system itself.
107  
108 =cut
109  
110  
111 __END__
« LibXML/Cache/Base.pm ↑ Summary LibXML/Cache.pm »