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';
new method, as well as methods TIEHASH, EXISTS and CLEAR. The Tie::StdHash package provides most methods required for hashes in the perltie manpage. 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 the 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. See the the perltie manpage section for more detailed descriptive, as well as example code:
tie %hash, classname. Associates a new hash instance with the specified class. LIST would represent additional arguments (along the lines of the AnyDBM_File manpage and compatriots) needed to complete the association.
DESTROY as a necessary method for tied hashes. Neither Tie::Hash nor 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.