Update of /cvsroot/perl-xml/xml-simple/t
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26018/t
Modified Files:
B_Hooks.t
Log Message:
- refactor cache handling routines for easier overriding
Index: B_Hooks.t
===================================================================
RCS file: /cvsroot/perl-xml/xml-simple/t/B_Hooks.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- B_Hooks.t 8 Oct 2006 07:44:26 -0000 1.1
+++ B_Hooks.t 12 Oct 2006 08:57:52 -0000 1.2
@@ -3,8 +3,9 @@
use strict;
use Test::More;
+use File::Spec;
-plan tests => 4;
+plan tests => 12;
use_ok('XML::Simple');
@@ -64,4 +65,72 @@
}
+
+my $xs = XML::Simple->new(cache => 'storable');
+my $sx = ElbarotsXS->new(cache => 'storable');
+
+isa_ok($sx, 'XML::Simple', 'object of class ElbarotsXS');
+
+my $src_file = File::Spec->catfile('t', 'test1.xml');
+
+is(
+ $xs->storable_filename($src_file),
+ File::Spec->catfile('t', 'test1.stor'),
+ 'default storable cache filename looks good'
+);
+
+my $cache_file = File::Spec->catfile('t', '1tset.stor'),;
+is(
+ $sx->storable_filename($src_file),
+ $cache_file,
+ 'overridden storable cache filename looks good'
+);
+
+SKIP: {
+ eval { require Storable };
+
+ skip "Storable not installed", 2 if $@;
+
+ unlink($cache_file),
+ ok(! -e $cache_file, 'overridden cache file does not exist before parse');
+ my $data = $sx->xml_in($src_file);
+ ok(-e $cache_file, 'overridden cache file does exist after parse');
+ unlink($cache_file),
+}
+
+my $data = eval {
+ $xs = XML::Simple->new(cache => 'floogle');
+ $xs->xml_in($src_file);
+};
+ok($@, 'bad cache scheme was rejected');
+
+$data = eval {
+ $sx = ElbarotsXS->new(cache => 'floogle');
+ $sx->xml_in($src_file);
+};
+ok(! $@, 'custom cache scheme was not rejected');
+is_deeply(
+ $data,
+ { data => 'floogle' },
+ 'custom cache reading method delivered the goods'
+);
+
exit 0;
+
+
+package ElbarotsXS;
+
+use base 'XML::Simple';
+
+sub storable_filename {
+ my($self, $path) = @_;
+
+ my($vol, $dir, $file) = File::Spec->splitpath( $path );
+ $file =~ s{\.xml$}{};
+
+ return File::Spec->catpath($vol, $dir, reverse($file) . '.stor');
+}
+
+sub cache_read_floogle {
+ return { data => 'floogle' };
+}
|