PATCH: Tie::SubstrHash
[p5sagit/p5-mst-13.2.git] / lib / Tie / Hash.pm
index 161771a..91ccbee 100644 (file)
@@ -1,51 +1,56 @@
-package TieHash;
+package Tie::Hash;
+
+our $VERSION = '1.00';
 
 =head1 NAME
 
-TieHash, TieHash::Std - base class definitions for tied hashes
+Tie::Hash, Tie::StdHash - base class definitions for tied hashes
 
 =head1 SYNOPSIS
 
     package NewHash;
-    require TieHash;
-    
-    @ISA = (TieHash);
-    
+    require Tie::Hash;
+
+    @ISA = (Tie::Hash);
+
     sub DELETE { ... }         # Provides needed method
     sub CLEAR { ... }          # Overrides inherited method
-    
-    
+
+
     package NewStdHash;
-    require TieHash;
-    
-    @ISA = (TieHash::Std);
-    
+    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;
+
+    tie %new_hash, 'NewHash';
+    tie %new_std_hash, 'NewStdHash';
 
 =head1 DESCRIPTION
 
 This module provides some skeletal methods for hash-tying classes. See
-L<perlfunc/tie> for a list of the functions required in order to tie a hash
-to a package. The basic B<TieHash> package provides a C<new> method, as well
-as methods C<TIEHASH>, C<EXISTS> and C<CLEAR>. The B<TieHash::Std> package
-provides most methods required for hashes in L<perlfunc/tie>. It inherits from
-B<TieHash>, and causes tied hashes to behave exactly like standard hashes,
-allowing for selective overloading of methods. The B<new> method is provided
-as grandfathering in the case a class forgets to include a B<TIEHASH> method.
+L<perltie> for a list of the functions required in order to tie a hash
+to a package. The basic B<Tie::Hash> package provides a C<new> method, as well
+as methods C<TIEHASH>, C<EXISTS> and C<CLEAR>. The B<Tie::StdHash> package
+provides most methods required for hashes in L<perltie>. It inherits from
+B<Tie::Hash>, and causes tied hashes to behave exactly like standard hashes,
+allowing for selective overloading of methods. The C<new> method is provided
+as grandfathering in the case a class forgets to include a C<TIEHASH> method.
 
 For developers wishing to write their own tied hashes, the required methods
-are:
+are briefly defined below. See the L<perltie> section for more detailed
+descriptive, as well as example code:
+
+=over 4
 
 =item TIEHASH classname, LIST
 
-The method invoked by the command C<tie %hash, class>. Associates a new
+The method invoked by the command C<tie %hash, classname>. Associates a new
 hash instance with the specified class. C<LIST> would represent additional
 arguments (along the lines of L<AnyDBM_File> and compatriots) needed to
 complete the association.
@@ -60,16 +65,18 @@ Retrieve the datum in I<key> for the tied hash I<this>.
 
 =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<key> exists with the tied hash I<this>.
 
+The B<Tie::Hash> implementation is a stub that simply croaks.
+
 =item DELETE this, key
 
 Delete the key I<key> from the tied hash I<this>.
@@ -82,23 +89,22 @@ Clear all values from the tied hash I<this>.
 
 =head1 CAVEATS
 
-The L<perlfunc/tie> documentation includes a method called C<DESTROY> as
-a necessary method for tied hashes. Neither B<TieHash> nor B<TieHash::Std>
-define a default for this method.
-
-The C<CLEAR> method provided by these two packages is not listed in the
-L<perlfunc/tie> section.
+The L<perltie> documentation includes a method called C<DESTROY> as
+a necessary method for tied hashes. Neither B<Tie::Hash> nor B<Tie::StdHash>
+define a default for this method. This is a standard for class packages,
+but may be omitted in favor of a simple default.
 
 =head1 MORE INFORMATION
 
-The packages relating to various DBM-related implemetations (F<DB_File>,
+The packages relating to various DBM-related implementations (F<DB_File>,
 F<NDBM_File>, etc.) show examples of general tied hashes, as does the
-L<Config> module. While these do not utilize B<TieHash>, they serve as
+L<Config> module. While these do not utilize B<Tie::Hash>, they serve as
 good working examples.
 
 =cut
-    
+
 use Carp;
+use warnings::register;
 
 sub new {
     my $pkg = shift;
@@ -109,9 +115,8 @@ sub new {
 
 sub TIEHASH {
     my $pkg = shift;
-    if (defined &{"{$pkg}::new"}) {
-       carp "WARNING: calling ${pkg}->new since ${pkg}->TIEHASH is missing"
-           if $^W;
+    if (defined &{"${pkg}::new"}) {
+       warnings::warnif("WARNING: calling ${pkg}->new since ${pkg}->TIEHASH is missing");
        $pkg->new(@_);
     }
     else {
@@ -138,12 +143,12 @@ sub CLEAR {
     }
 }
 
-# The TieHash::Std package implements standard perl hash behaviour.
+# The Tie::StdHash package implements standard perl hash behaviour.
 # It exists to act as a base class for classes which only wish to
 # alter some parts of their behaviour.
 
-package TieHash::Std;
-@ISA = qw(TieHash);
+package Tie::StdHash;
+@ISA = qw(Tie::Hash);
 
 sub TIEHASH  { bless {}, $_[0] }
 sub STORE    { $_[0]->{$_[1]} = $_[2] }