Tie::Hash, Tie::StdHash - Base Class Definitions for Tied Hashes

package NewHash; require Tie::Hash; @ISA = (Tie::Hash); sub DELETE {
 ...
}
# Provides additional method sub CLEAR {
 ...
}
# Overrides inherited method package NewStdHash; require Tie::Hash; @ISA = (Tie::StdHash); sub DELETE {
 ...
}
package main; tie %new_hash, "NewHash"; tie %new_std_hash, "NewStdHash";

This module provides some skeletal methods for hash-tying classes. (See for a list of the functions required in order to tie a hash to a package.) The basic Tie::Hash package provides a new() method, as well as methods TIEHASH(), EXISTS() and CLEAR(). The Tie::StdHash package provides most methods required for hashes. It inherits from Tie::Hash, and causes tied hashes to behave exactly like standard hashes, allowing for selective overloading of methods. The new() method is provided as grandfathering in case a class forgets to include a TIEHASH() method.

For developers wishing to write their own tied hashes, the required methods are briefly defined below. ( not only documents these methods, but also has sample code.)

includes a method called DESTROY() as a "necessary" method for tied hashes. However, it is not actually required, and neither Tie::Hash nor Tie::StdHash defines a default for this method.

See also

The library modules relating to various DBM-related implementations (DB_File, GDBM_File, NDBM_File, ODBM_File, and SDBM_File) show examples of general tied hashes, as does the Config module. While these modules do not utilize Tie::Hash, they serve as good working examples.