xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Memoize/NDBM_File.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage Memoize::NDBM_File;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gate=head1 NAME
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gateMemoize::NDBM_File - glue to provide EXISTS for NDBM_File for Storable use
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 NDBM_File;
14*0Sstevel@tonic-gate@ISA = qw(NDBM_File);
15*0Sstevel@tonic-gate$VERSION = 0.65;
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate$Verbose = 0;
18*0Sstevel@tonic-gate
19*0Sstevel@tonic-gatesub AUTOLOAD {
20*0Sstevel@tonic-gate  warn "Nonexistent function $AUTOLOAD invoked in Memoize::NDBM_File\n";
21*0Sstevel@tonic-gate}
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gatesub import {
24*0Sstevel@tonic-gate  warn "Importing Memoize::NDBM_File\n" if $Verbose;
25*0Sstevel@tonic-gate}
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gatemy %keylist;
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate# This is so ridiculous...
31*0Sstevel@tonic-gatesub _backhash {
32*0Sstevel@tonic-gate  my $self = shift;
33*0Sstevel@tonic-gate  my %fakehash;
34*0Sstevel@tonic-gate  my $k;
35*0Sstevel@tonic-gate  for ($k = $self->FIRSTKEY(); defined $k; $k = $self->NEXTKEY($k)) {
36*0Sstevel@tonic-gate    $fakehash{$k} = undef;
37*0Sstevel@tonic-gate  }
38*0Sstevel@tonic-gate  $keylist{$self} = \%fakehash;
39*0Sstevel@tonic-gate}
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gatesub EXISTS {
42*0Sstevel@tonic-gate  warn "Memoize::NDBM_File EXISTS (@_)\n" if $Verbose;
43*0Sstevel@tonic-gate  my $self = shift;
44*0Sstevel@tonic-gate  _backhash($self)  unless exists $keylist{$self};
45*0Sstevel@tonic-gate  my $r = exists $keylist{$self}{$_[0]};
46*0Sstevel@tonic-gate  warn "Memoize::NDBM_File EXISTS (@_) ==> $r\n" if $Verbose;
47*0Sstevel@tonic-gate  $r;
48*0Sstevel@tonic-gate}
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gatesub DEFINED {
51*0Sstevel@tonic-gate  warn "Memoize::NDBM_File DEFINED (@_)\n" if $Verbose;
52*0Sstevel@tonic-gate  my $self = shift;
53*0Sstevel@tonic-gate  _backhash($self)  unless exists $keylist{$self};
54*0Sstevel@tonic-gate  defined $keylist{$self}{$_[0]};
55*0Sstevel@tonic-gate}
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gatesub DESTROY {
58*0Sstevel@tonic-gate  warn "Memoize::NDBM_File DESTROY (@_)\n" if $Verbose;
59*0Sstevel@tonic-gate  my $self = shift;
60*0Sstevel@tonic-gate  delete $keylist{$self};   # So much for reference counting...
61*0Sstevel@tonic-gate  $self->SUPER::DESTROY(@_);
62*0Sstevel@tonic-gate}
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate# Maybe establish the keylist at TIEHASH time instead?
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gatesub STORE {
67*0Sstevel@tonic-gate  warn "Memoize::NDBM_File STORE (@_)\n" if $VERBOSE;
68*0Sstevel@tonic-gate  my $self = shift;
69*0Sstevel@tonic-gate  $keylist{$self}{$_[0]} = undef;
70*0Sstevel@tonic-gate  $self->SUPER::STORE(@_);
71*0Sstevel@tonic-gate}
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate# Inherit FETCH and TIEHASH
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate1;
78