xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Memoize/Storable.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage Memoize::Storable;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate=head1 NAME
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateMemoize::Storable - store Memoized data in Storable database
6*0Sstevel@tonic-gate
7*0Sstevel@tonic-gate=head1 DESCRIPTION
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gateSee L<Memoize>.
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate=cut
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gateuse Storable ();
14*0Sstevel@tonic-gate$VERSION = 0.65;
15*0Sstevel@tonic-gate$Verbose = 0;
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gatesub TIEHASH {
18*0Sstevel@tonic-gate  require Carp if $Verbose;
19*0Sstevel@tonic-gate  my $package = shift;
20*0Sstevel@tonic-gate  my $filename = shift;
21*0Sstevel@tonic-gate  my $truehash = (-e $filename) ? Storable::retrieve($filename) : {};
22*0Sstevel@tonic-gate  my %options;
23*0Sstevel@tonic-gate  print STDERR "Memoize::Storable::TIEHASH($filename, @_)\n" if $Verbose;
24*0Sstevel@tonic-gate  @options{@_} = ();
25*0Sstevel@tonic-gate  my $self =
26*0Sstevel@tonic-gate    {FILENAME => $filename,
27*0Sstevel@tonic-gate     H => $truehash,
28*0Sstevel@tonic-gate     OPTIONS => \%options
29*0Sstevel@tonic-gate    };
30*0Sstevel@tonic-gate  bless $self => $package;
31*0Sstevel@tonic-gate}
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gatesub STORE {
34*0Sstevel@tonic-gate  require Carp if $Verbose;
35*0Sstevel@tonic-gate  my $self = shift;
36*0Sstevel@tonic-gate  print STDERR "Memoize::Storable::STORE(@_)\n" if $Verbose;
37*0Sstevel@tonic-gate  $self->{H}{$_[0]} = $_[1];
38*0Sstevel@tonic-gate}
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gatesub FETCH {
41*0Sstevel@tonic-gate  require Carp if $Verbose;
42*0Sstevel@tonic-gate  my $self = shift;
43*0Sstevel@tonic-gate  print STDERR "Memoize::Storable::FETCH(@_)\n" if $Verbose;
44*0Sstevel@tonic-gate  $self->{H}{$_[0]};
45*0Sstevel@tonic-gate}
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gatesub EXISTS {
48*0Sstevel@tonic-gate  require Carp if $Verbose;
49*0Sstevel@tonic-gate  my $self = shift;
50*0Sstevel@tonic-gate  print STDERR "Memoize::Storable::EXISTS(@_)\n" if $Verbose;
51*0Sstevel@tonic-gate  exists $self->{H}{$_[0]};
52*0Sstevel@tonic-gate}
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gatesub DESTROY {
55*0Sstevel@tonic-gate  require Carp if $Verbose;
56*0Sstevel@tonic-gate  my $self= shift;
57*0Sstevel@tonic-gate  print STDERR "Memoize::Storable::DESTROY(@_)\n" if $Verbose;
58*0Sstevel@tonic-gate  if ($self->{OPTIONS}{'nstore'}) {
59*0Sstevel@tonic-gate    Storable::nstore($self->{H}, $self->{FILENAME});
60*0Sstevel@tonic-gate  } else {
61*0Sstevel@tonic-gate    Storable::store($self->{H}, $self->{FILENAME});
62*0Sstevel@tonic-gate  }
63*0Sstevel@tonic-gate}
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gatesub FIRSTKEY {
66*0Sstevel@tonic-gate  'Fake hash from Memoize::Storable';
67*0Sstevel@tonic-gate}
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gatesub NEXTKEY {
70*0Sstevel@tonic-gate  undef;
71*0Sstevel@tonic-gate}
72*0Sstevel@tonic-gate1;
73