Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: nwellnhof/XML-LibXML-Cache
base: 6ee8efd786
...
head fork: nwellnhof/XML-LibXML-Cache
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
13 Changes
@@ -0,0 +1,13 @@
+Revision history for Perl module XML::LibXML::Cache
+
+0.12 2012-08-24
+ - Add cache_hits method
+
+0.11 2012-08-18
+ - Fix tests to work with XML::LibXML 1.99 and later
+ - Fix tests to work with XML catalogs
+ - Documentation fixes
+
+0.10 2011-09-10
+ - Initial release
+
View
6 dist.ini
@@ -1,5 +1,5 @@
name = XML-LibXML-Cache
-version = 0.10
+version = 0.12
author = Nick Wellnhofer <wellnhofer@aevum.de>
license = Perl_5
copyright_holder = Nick Wellnhofer
@@ -7,6 +7,7 @@ copyright_holder = Nick Wellnhofer
[@Basic]
[PkgVersion]
+[PodCoverageTests]
[PodSyntaxTests]
[PodWeaver]
@@ -15,6 +16,9 @@ perl = 5.008
URI = 0
XML::LibXML = 1.59
+[Prereqs / Suggests]
+XML::LibXSLT = 1.59
+
[Prereqs / TestRequires]
File::Touch = 0
Test::Deep = 0
View
3  lib/XML/LibXML/Cache.pm
@@ -1,5 +1,6 @@
package XML::LibXML::Cache;
use strict;
+use warnings;
# ABSTRACT: Document cache for XML::LibXML
@@ -77,7 +78,7 @@ Creates a new cache. Valid options are:
=item parser
The L<XML::LibXML> parser object that should be used to load documents if you
-want to use certain parser options. If this options is missing a parser
+want to use certain parser options. If this option is missing a parser
with default options will be used.
=back
View
29 lib/XML/LibXML/Cache/Base.pm
@@ -1,5 +1,6 @@
package XML::LibXML::Cache::Base;
use strict;
+use warnings;
# ABSTRACT: Base class for XML::LibXML caches
@@ -19,17 +20,29 @@ my $deps_found;
sub new {
my $class = shift;
- my $self = { cache => {} };
+ my $self = {
+ cache => {},
+ hits => 0,
+ };
return bless($self, $class);
}
+sub cache_hits {
+ my $self = shift;
+
+ return $self->{hits};
+}
+
sub _cache_lookup {
my ($self, $filename, $get_item) = @_;
my $item = $self->_cache_read($filename);
- return $item if $item;
+ if ($item) {
+ ++$self->{hits};
+ return $item;
+ }
$deps_found = {};
@@ -116,5 +129,17 @@ __END__
Base class for the document and style sheet caches.
+=head1 METHODS
+
+=head2 new
+
+Only used by subclasses.
+
+=head2 cache_hits
+
+ my $hits = $cache->cache_hits;
+
+Return the number of cache hits.
+
=cut
View
1  lib/XML/LibXSLT/Cache.pm
@@ -1,5 +1,6 @@
package XML::LibXSLT::Cache;
use strict;
+use warnings;
# ABSTRACT: Style sheet cache for XML::LibXSLT
View
44 t/xml.t
@@ -2,7 +2,7 @@
use strict;
use File::Touch;
-use Test::More tests => 7;
+use Test::More tests => 14;
use Test::Deep;
$ENV{XML_CATALOG_FILES} = '';
@@ -26,22 +26,42 @@ isa_ok($cached_rec, 'ARRAY');
my ($cached_doc, $deps) = @$cached_rec;
is($cached_doc, $doc, 'cached doc');
-my $number = re(qr/^\d+\z/);
-my $attrs = [ $number, $number ];
-cmp_deeply($deps, {
- $filename => $attrs,
- $entity_filename => $attrs,
- 't/xml/test01.dtd' => $attrs,
- 't/xml/test01-include.xml' => $attrs,
- 't/xml/test01-missing.xml' => [ -1, -1 ],
-}, 'dependencies');
+my $hits = $cache->cache_hits;
+is($hits, 0, 'cache hits before');
+
+my $number = re(qr/^\d+\z/);
+my $numbers = [ $number, $number ];
+
+cmp_deeply($deps->{$filename}, $numbers, 'dependency on self');
+cmp_deeply($deps->{'t/xml/test01.dtd'}, $numbers, 'dependency on dtd');
+cmp_deeply(
+ $deps->{$entity_filename},
+ $numbers,
+ 'dependency on external entity',
+);
+cmp_deeply(
+ $deps->{'t/xml/test01-include.xml'},
+ $numbers,
+ 'dependency on xinclude',
+);
+cmp_deeply(
+ $deps->{'t/xml/test01-missing.xml'},
+ [ -1, -1 ],
+ 'dependency on missing xinclude',
+);
$cached_doc = $cache->parse_file($filename);
-is($cached_doc, $doc, 'cached doc');
+is(int($cached_doc), int($doc), 'cached doc');
+
+$hits = $cache->cache_hits;
+is($hits, 1, 'cache hits after');
$ref = File::Touch->new(mtime => $time, no_create => 1);
$ref->touch($entity_filename);
my $new_doc = $cache->parse_file($filename);
-isnt($new_doc, $doc, 'new doc');
+isnt(int($new_doc), int($doc), 'new doc');
+
+$hits = $cache->cache_hits;
+is($hits, 1, 'cache hits after');
View
4 t/xsl.t
@@ -21,7 +21,7 @@ my $cached_rec = $cache->{cache}{$filename};
isa_ok($cached_rec, 'ARRAY');
my ($cached_ss, $deps) = @$cached_rec;
-is($cached_ss, $stylesheet, 'cached stylesheet');
+is(int($cached_ss), int($stylesheet), 'cached stylesheet');
my $number = re(qr/^\d+\z/);
my $attrs = [ $number, $number ];
@@ -42,5 +42,5 @@ $ref = File::Touch->new(mtime => $time, no_create => 1);
$ref->touch($import_filename);
my $new_ss = $cache->parse_stylesheet_file($filename);
-isnt($new_ss, $stylesheet, 'new stylesheet');
+isnt(int($new_ss), int($stylesheet), 'new stylesheet');

No commit comments for this range

Something went wrong with that request. Please try again.