File Coverage

blib/lib/Memoize/Storable.pm
Criterion Covered Total %
statement 31 33 93.9
branch 9 14 64.2
condition n/a
subroutine 8 10 80.0
pod n/a
total 48 57 84.2


line stmt bran cond sub pod time code
1 1     1   2519 use strict; use warnings;
  1     1   2  
  1         39  
  1         6  
  1         2  
  1         98  
2              
3             package Memoize::Storable;
4             our $VERSION = '1.17';
5              
6 1     1   724 use Storable 1.002 (); # for lock_* function variants
  1         5411  
  1         682  
7              
8             our $Verbose;
9              
10             sub TIEHASH {
11 5     5   167721 my $package = shift;
12 5         10 my $filename = shift;
13 5 100       102 my $truehash = (-e $filename) ? Storable::lock_retrieve($filename) : {};
14 5         250 my %options;
15 5 50       18 print STDERR "Memoize::Storable::TIEHASH($filename, @_)\n" if $Verbose;
16 5         16 @options{@_} = (1) x @_;
17 5         25 my $self =
18             {FILENAME => $filename,
19             H => $truehash,
20             OPTIONS => \%options
21             };
22 5         38 bless $self => $package;
23             }
24              
25             sub STORE {
26 1     1   2 my $self = shift;
27 1 50       3 print STDERR "Memoize::Storable::STORE(@_)\n" if $Verbose;
28 1         6 $self->{H}{$_[0]} = $_[1];
29             }
30              
31             sub FETCH {
32 2     2   5 my $self = shift;
33 2 50       7 print STDERR "Memoize::Storable::FETCH(@_)\n" if $Verbose;
34 2         17 $self->{H}{$_[0]};
35             }
36              
37             sub EXISTS {
38 4     4   1026 my $self = shift;
39 4 50       14 print STDERR "Memoize::Storable::EXISTS(@_)\n" if $Verbose;
40 4         29 exists $self->{H}{$_[0]};
41             }
42              
43             sub DESTROY {
44 5     5   26 my $self= shift;
45 5 50       14 print STDERR "Memoize::Storable::DESTROY(@_)\n" if $Verbose;
46 5 100       17 if ($self->{OPTIONS}{'nstore'}) {
47 1         8 Storable::lock_nstore($self->{H}, $self->{FILENAME});
48             } else {
49 4         18 Storable::lock_store($self->{H}, $self->{FILENAME});
50             }
51             }
52              
53             sub FIRSTKEY {
54 0     0     'Fake hash from Memoize::Storable';
55             }
56              
57             sub NEXTKEY {
58 0     0     undef;
59             }
60              
61             1;
62              
63             __END__