diff options
author | Norbert Preining <norbert@preining.info> | 2024-03-15 03:06:35 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2024-03-15 03:06:35 +0000 |
commit | 12679ab7d3c2a210f4123163671b532b8b55d5f9 (patch) | |
tree | 0060d13467186ad977f4e73488ee20dd6c0017ab /systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm | |
parent | 62170822e034fdd3f81de7274835d0d3b0467100 (diff) |
CTAN sync 202403150306
Diffstat (limited to 'systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm')
-rw-r--r-- | systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm | 85 |
1 files changed, 23 insertions, 62 deletions
diff --git a/systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm b/systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm index ff934c656b..fc29f79986 100644 --- a/systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm +++ b/systems/texlive/tlnet/tlpkg/tlperl/lib/Memoize/NDBM_File.pm @@ -1,77 +1,38 @@ -package Memoize::NDBM_File; - -=head1 NAME - -Memoize::NDBM_File - glue to provide EXISTS for NDBM_File for Storable use - -=head1 DESCRIPTION +use strict; use warnings; -See L<Memoize>. - -=cut +package Memoize::NDBM_File; +our $VERSION = '1.16'; use NDBM_File; -@ISA = qw(NDBM_File); -$VERSION = '1.03'; - -$Verbose = 0; +our @ISA = qw(NDBM_File); -sub AUTOLOAD { - warn "Nonexistent function $AUTOLOAD invoked in Memoize::NDBM_File\n"; -} - -sub import { - warn "Importing Memoize::NDBM_File\n" if $Verbose; +# NDBM_File cannot store undef and will store an empty string if you try +# but it does return undef if you try to read a non-existent key +# so we can emulate exists() using defined() +sub EXISTS { + defined shift->FETCH(@_); } +# Perl 5.37.3 adds this EXISTS emulation to NDBM_File itself +delete $Memoize::NDBM_File::{'EXISTS'} + if eval { NDBM_File->VERSION( '1.16' ) }; -my %keylist; - -# This is so ridiculous... -sub _backhash { - my $self = shift; - my %fakehash; - my $k; - for ($k = $self->FIRSTKEY(); defined $k; $k = $self->NEXTKEY($k)) { - $fakehash{$k} = undef; - } - $keylist{$self} = \%fakehash; -} - -sub EXISTS { - warn "Memoize::NDBM_File EXISTS (@_)\n" if $Verbose; - my $self = shift; - _backhash($self) unless exists $keylist{$self}; - my $r = exists $keylist{$self}{$_[0]}; - warn "Memoize::NDBM_File EXISTS (@_) ==> $r\n" if $Verbose; - $r; -} +1; -sub DEFINED { - warn "Memoize::NDBM_File DEFINED (@_)\n" if $Verbose; - my $self = shift; - _backhash($self) unless exists $keylist{$self}; - defined $keylist{$self}{$_[0]}; -} +__END__ -sub DESTROY { - warn "Memoize::NDBM_File DESTROY (@_)\n" if $Verbose; - my $self = shift; - delete $keylist{$self}; # So much for reference counting... - $self->SUPER::DESTROY(@_); -} +=pod -# Maybe establish the keylist at TIEHASH time instead? +=head1 NAME -sub STORE { - warn "Memoize::NDBM_File STORE (@_)\n" if $VERBOSE; - my $self = shift; - $keylist{$self}{$_[0]} = undef; - $self->SUPER::STORE(@_); -} +Memoize::NDBM_File - glue to provide EXISTS for NDBM_File for Storable use +=head1 DESCRIPTION +This class provides L<EXISTS|perltie/C<EXISTS>> support for L<NDBM_File>. -# Inherit FETCH and TIEHASH +L<In Perl 5.37.3|https://github.com/Perl/perl5/commit/c0a1a377c02ed789f5eff667f46a2314a05c5a4c>, +support for C<EXISTS> was added to L<NDBM_File> itself. +Code which requires such a perl should simply use L<NBDM_File> directly. -1; +=cut |