X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTie%2FHash.pm;h=86d253d6d647aca27a5c3974777a0b0b189faf40;hb=c595d0543e6b5fbcaf00be87ff6162c56aa65a75;hp=c28e828d573f8a3dded29e9c24fe09f6377bfaf8;hpb=15634f32600dfd7c267231a107a89655e6a68433;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Tie/Hash.pm b/lib/Tie/Hash.pm index c28e828..86d253d 100644 --- a/lib/Tie/Hash.pm +++ b/lib/Tie/Hash.pm @@ -1,6 +1,6 @@ package Tie::Hash; -our $VERSION = '1.00'; +our $VERSION = '1.02'; =head1 NAME @@ -11,7 +11,7 @@ Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes package NewHash; require Tie::Hash; - @ISA = (Tie::Hash); + @ISA = qw(Tie::Hash); sub DELETE { ... } # Provides needed method sub CLEAR { ... } # Overrides inherited method @@ -20,7 +20,7 @@ Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes package NewStdHash; require Tie::Hash; - @ISA = (Tie::StdHash); + @ISA = qw(Tie::StdHash); # All methods provided by default, define only those needing overrides # Accessors access the storage in %{$_[0]}; @@ -30,7 +30,7 @@ Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes package NewExtraHash; require Tie::Hash; - @ISA = (Tie::ExtraHash); + @ISA = qw(Tie::ExtraHash); # All methods provided by default, define only those needing overrides # Accessors access the storage in %{$_[0][0]}; @@ -38,7 +38,8 @@ Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes # the reference to the actual storage sub DELETE { $_[0][1]->('del', $_[0][0], $_[1]); # Call the report writer - delete $_[0][0]->{$_[1]}; # $_[0]->SUPER::DELETE($_[1]) } + delete $_[0][0]->{$_[1]}; # $_[0]->SUPER::DELETE($_[1]) + } package main; @@ -104,6 +105,13 @@ Delete the key I from the tied hash I. Clear all values from the tied hash I. +=item SCALAR this + +Returns what evaluating the hash in scalar context yields. + +B does not implement this method (but B +and B do). + =back =head1 Inheriting from B @@ -130,7 +138,7 @@ should operate on the hash referenced by the first argument: =head1 Inheriting from B The accessor methods assume that the actual storage for the data in the tied -hash is in the hash referenced by C<(tied(%tiedhash))[0]>. Thus overwritten +hash is in the hash referenced by C<(tied(%tiedhash))-E[0]>. Thus overwritten C method should return an array reference with the first element being a hash reference, and the remaining methods should operate on the hash C<< %{ $_[0]->[0] } >>: @@ -155,15 +163,18 @@ same storage algorithm as in TIEHASH subroutine above. Hence, a typical package inheriting from B does not need to overwrite this method. -=head1 C and C +=head1 C, C and C The methods C and C are not defined in B, B, or B. Tied hashes do not require -presense of these methods, but if defined, the methods will be called in +presence of these methods, but if defined, the methods will be called in proper time, see L. +C is only defined in B and B. + If needed, these methods should be defined by the package inheriting from -B, B, or B. +B, B, or B. See L +to find out what happens when C does not exist. =head1 MORE INFORMATION @@ -229,6 +240,7 @@ sub NEXTKEY { each %{$_[0]} } sub EXISTS { exists $_[0]->{$_[1]} } sub DELETE { delete $_[0]->{$_[1]} } sub CLEAR { %{$_[0]} = () } +sub SCALAR { scalar %{$_[0]} } package Tie::ExtraHash; @@ -240,5 +252,6 @@ sub NEXTKEY { each %{$_[0][0]} } sub EXISTS { exists $_[0][0]->{$_[1]} } sub DELETE { delete $_[0][0]->{$_[1]} } sub CLEAR { %{$_[0][0]} = () } +sub SCALAR { scalar %{$_[0][0]} } 1;