X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTie%2FHash.pm;h=86d253d6d647aca27a5c3974777a0b0b189faf40;hb=46471bde41ad0777edf7b89818df6730e8b55c20;hp=65f9dd0b3851eae4e8a8be47fbda06e15e7481c2;hpb=96820f7c3e2b653f17592caf375543507ca51b58;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Tie/Hash.pm b/lib/Tie/Hash.pm index 65f9dd0..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]}; @@ -105,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 @@ -131,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] } >>: @@ -156,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 @@ -230,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; @@ -241,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;