Skip to content

Commit

Permalink
Release 0.03
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Sep 29, 2019
1 parent 23f6081 commit 1d8f3c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Revision history for Class::Simple::Readonly::Cached

0.03
Added the objet() method
0.03 Sun Sep 29 05:12:19 PDT 2019
Added the object() method

0.02 Fri Sep 27 03:43:56 PDT 2019
Added hash mode
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class::Simple::Readonly::Cached - cache messages to an object

# VERSION

Version 0.02
Version 0.03

# SYNOPSIS

Expand Down Expand Up @@ -35,6 +35,10 @@ which is an object which is taken to be the object to be cached.
If not given, an object of the class [Class::Simple](https://metacpan.org/pod/Class::Simple) is instantiated
and that is used.

## object

Return the encapsulated objet

# AUTHOR

Nigel Horne, `<njh at bandsman.co.uk>`
Expand Down
31 changes: 17 additions & 14 deletions lib/Class/Simple/Readonly/Cached.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Class::Simple::Readonly::Cached - cache messages to an object
=head1 VERSION
Version 0.02
Version 0.03
=cut

our $VERSION = '0.02';
our $VERSION = '0.03';

=head1 SYNOPSIS
Expand Down Expand Up @@ -67,14 +67,15 @@ sub new {
%args = @_;
}

if(!$args{'cache'}) {
Carp::carp('Usage: ', __PACKAGE__, '->new(cache => $cache [, object => $object ], %args)');
}

if(!defined($args{'object'})) {
$args{'object'} = Class::Simple->new(%args);
}

if($args{'cache'}) {
return bless \%args, $class;
}
Carp::carp('Usage: ', __PACKAGE__, '->new(cache => $cache [, object => $object ], %args)');
return bless \%args, $class;
}

=head2 object
Expand Down Expand Up @@ -109,16 +110,18 @@ sub AUTOLOAD {
my $cache = $self->{'cache'};

if($param eq 'DESTROY') {
if(ref($cache) eq 'HASH') {
foreach my $key(keys %{$cache}) {
delete $cache->{$key};
if($cache) {
if(ref($cache) eq 'HASH') {
foreach my $key(keys %{$cache}) {
delete $cache->{$key};
}
return;
}
return;
}
if(defined($^V) && ($^V ge 'v5.14.0')) {
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; # >= 5.14.0 only
if(defined($^V) && ($^V ge 'v5.14.0')) {
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; # >= 5.14.0 only
}
$cache->clear();
}
$cache->clear();
return;
}

Expand Down

0 comments on commit 1d8f3c0

Please sign in to comment.