X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTie%2FHash.pm;h=91ccbee19edd2a8c2c517c949248c618b33b5dd4;hb=28ee103ac832b2460303989eadcfcb79549ff93c;hp=89fd61dd74b5f2c9333e07a8caf7d8560d025415;hpb=cc6b73957505a73b130c87add7bf3d534f129041;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Tie/Hash.pm b/lib/Tie/Hash.pm index 89fd61d..91ccbee 100644 --- a/lib/Tie/Hash.pm +++ b/lib/Tie/Hash.pm @@ -1,5 +1,7 @@ package Tie::Hash; +our $VERSION = '1.00'; + =head1 NAME Tie::Hash, Tie::StdHash - base class definitions for tied hashes @@ -8,24 +10,24 @@ Tie::Hash, Tie::StdHash - base class definitions for tied hashes package NewHash; require Tie::Hash; - + @ISA = (Tie::Hash); - + sub DELETE { ... } # Provides needed method sub CLEAR { ... } # Overrides inherited method - - + + package NewStdHash; require Tie::Hash; - + @ISA = (Tie::StdHash); - + # All methods provided by default, define only those needing overrides sub DELETE { ... } - - + + package main; - + tie %new_hash, 'NewHash'; tie %new_std_hash, 'NewStdHash'; @@ -44,7 +46,7 @@ For developers wishing to write their own tied hashes, the required methods are briefly defined below. See the L section for more detailed descriptive, as well as example code: -=over +=over 4 =item TIEHASH classname, LIST @@ -63,16 +65,18 @@ Retrieve the datum in I for the tied hash I. =item FIRSTKEY this -Return the (key, value) pair for the first key in the hash. +Return the first key in the hash. =item NEXTKEY this, lastkey -Return the next (key, value) pair for the hash. +Return the next key in the hash. =item EXISTS this, key Verify that I exists with the tied hash I. +The B implementation is a stub that simply croaks. + =item DELETE this, key Delete the key I from the tied hash I. @@ -92,7 +96,7 @@ but may be omitted in favor of a simple default. =head1 MORE INFORMATION -The packages relating to various DBM-related implemetations (F, +The packages relating to various DBM-related implementations (F, F, etc.) show examples of general tied hashes, as does the L module. While these do not utilize B, they serve as good working examples. @@ -100,6 +104,7 @@ good working examples. =cut use Carp; +use warnings::register; sub new { my $pkg = shift; @@ -111,8 +116,7 @@ sub new { sub TIEHASH { my $pkg = shift; if (defined &{"${pkg}::new"}) { - carp "WARNING: calling ${pkg}->new since ${pkg}->TIEHASH is missing" - if $^W; + warnings::warnif("WARNING: calling ${pkg}->new since ${pkg}->TIEHASH is missing"); $pkg->new(@_); } else {