X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTie%2FHash.pm;h=86d253d6d647aca27a5c3974777a0b0b189faf40;hb=46471bde41ad0777edf7b89818df6730e8b55c20;hp=397272becec0646a855f879d4e441ac60a10dea6;hpb=1db7d662ab3016c638481dc6ccd6dfc26c968f33;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Tie/Hash.pm b/lib/Tie/Hash.pm index 397272b..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,25 +20,26 @@ 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]}; - # TIEHANDLE should return a reference to the actual storage + # TIEHASH should return a reference to the actual storage sub DELETE { ... } 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]}; - # TIEHANDLE should return an array reference with the first element being + # TIEHASH should return an array reference with the first element being # 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,13 +105,20 @@ 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 The accessor methods assume that the actual storage for the data in the tied hash is in the hash referenced by C. Thus overwritten -C method should return a hash reference, and the remaining methods +C method should return a hash reference, and the remaining methods should operate on the hash referenced by the first argument: package ReportHash; @@ -130,8 +138,8 @@ 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 -C method should return an array reference with the first +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] } >>: @@ -149,21 +157,24 @@ hash C<< %{ $_[0]->[0] } >>: $_[0][0]{$_[1]} = $_[2] } -The default C method stores "extra" arguments to tie() starting +The default C method stores "extra" arguments to tie() starting from offset 1 in the array referenced by C; this is the 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;