diff --git a/Changes b/Changes index d693f3e..b18652c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Class::Simple::Cached +0.03 + Improved handling of caching functionas that return undef + 0.02 Thu 19 Sep 19:30:43 EDT 2019 Fix working with arrays diff --git a/lib/Class/Simple/Cached.pm b/lib/Class/Simple/Cached.pm index 04a421e..414bddb 100644 --- a/lib/Class/Simple/Cached.pm +++ b/lib/Class/Simple/Cached.pm @@ -105,6 +105,9 @@ sub AUTOLOAD { if(ref($rc) eq 'ARRAY') { return @{$rc}; } + if($rc eq __PACKAGE__ . ">UNDEF<") { + return; + } return $rc; } if(wantarray) { @@ -115,7 +118,12 @@ sub AUTOLOAD { $cache->set($param, \@rc, 'never'); return @rc; } - return $cache->set($param, $object->$func(), 'never'); + my $rc = $object->$func(); + if(!defined($rc)) { + $cache->set($param, __PACKAGE__ . ">UNDEF<", 'never'); + return; + } + return $cache->set($param, $rc, 'never'); } # $param = "SUPER::$param"; @@ -137,6 +145,8 @@ Nigel Horne, C<< >> =head1 BUGS +Doesn't work with L. + Please report any bugs or feature requests to C, or through the web interface at L. diff --git a/t/class.t b/t/class.t index a2d3acd..b99421e 100644 --- a/t/class.t +++ b/t/class.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::Most tests => 17; +use Test::Most tests => 19; use Test::NoWarnings; use CHI; @@ -29,6 +29,9 @@ CLASS: { ok(scalar(@a) == 1); ok($a[0] eq 'a'); + ok(!defined($l->empty())); + ok(!defined($l->empty())); + # White box test the cache ok($cache->get('barney') eq 'betty'); my $a = $cache->get('a'); @@ -71,6 +74,9 @@ sub a { return 'a'; } +sub empty { +} + sub calls { my $self = shift;