2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>Tie::ExtraHash - base class definitions for tied hashes
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> Tie::ExtraHash - base class definitions for tied hashes
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
25 <li><a href=
"#inheriting_from_tie__stdhash">Inheriting from
<strong>Tie::StdHash
</strong></a></li>
26 <li><a href=
"#inheriting_from_tie__extrahash">Inheriting from
<strong>Tie::ExtraHash
</strong></a></li>
27 <li><a href=
"#scalar__untie_and_destroy"><code>SCALAR
</code>,
<code>UNTIE
</code> and
<code>DESTROY
</code></a></li>
28 <li><a href=
"#more_information">MORE INFORMATION
</a></li>
35 <h1><a name=
"name">NAME
</a></h1>
36 <p>Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes
</p>
40 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
43 require Tie::Hash;
</pre>
45 @ISA = (Tie::Hash);
</pre>
47 sub DELETE { ... } # Provides needed method
48 sub CLEAR { ... } # Overrides inherited method
</pre>
51 require Tie::Hash;
</pre>
53 @ISA = (Tie::StdHash);
</pre>
55 # All methods provided by default, define only those needing overrides
56 # Accessors access the storage in %{$_[
0]};
57 # TIEHASH should return a reference to the actual storage
58 sub DELETE { ... }
</pre>
61 require Tie::Hash;
</pre>
63 @ISA = (Tie::ExtraHash);
</pre>
65 # All methods provided by default, define only those needing overrides
66 # Accessors access the storage in %{$_[
0][
0]};
67 # TIEHASH should return an array reference with the first element being
68 # the reference to the actual storage
70 $_[
0][
1]-
>('del', $_[
0][
0], $_[
1]); # Call the report writer
71 delete $_[
0][
0]-
>{$_[
1]}; # $_[
0]-
>SUPER::DELETE($_[
1])
76 tie %new_hash, 'NewHash';
77 tie %new_std_hash, 'NewStdHash';
78 tie %new_extra_hash, 'NewExtraHash',
79 sub {warn
"Doing \U$_[
1]\E of $_[
2].\n
"};
</pre>
83 <h1><a name=
"description">DESCRIPTION
</a></h1>
84 <p>This module provides some skeletal methods for hash-tying classes. See
85 <a href=
"file://C|\msysgit\mingw\html/pod/perltie.html">the perltie manpage
</a> for a list of the functions required in order to tie a hash
86 to a package. The basic
<strong>Tie::Hash
</strong> package provides a
<code>new
</code> method, as well
87 as methods
<code>TIEHASH
</code>,
<code>EXISTS
</code> and
<code>CLEAR
</code>. The
<strong>Tie::StdHash
</strong> and
88 <strong>Tie::ExtraHash
</strong> packages
89 provide most methods for hashes described in
<a href=
"file://C|\msysgit\mingw\html/pod/perltie.html">the perltie manpage
</a> (the exceptions
90 are
<code>UNTIE
</code> and
<code>DESTROY
</code>). They cause tied hashes to behave exactly like standard hashes,
91 and allow for selective overwriting of methods.
<strong>Tie::Hash
</strong> grandfathers the
92 <code>new
</code> method: it is used if
<code>TIEHASH
</code> is not defined
93 in the case a class forgets to include a
<code>TIEHASH
</code> method.
</p>
94 <p>For developers wishing to write their own tied hashes, the required methods
95 are briefly defined below. See the
<a href=
"file://C|\msysgit\mingw\html/pod/perltie.html">the perltie manpage
</a> section for more detailed
96 descriptive, as well as example code:
</p>
98 <dt><strong><a name=
"item_tiehash_classname_2c_list">TIEHASH classname, LIST
</a></strong>
101 <p>The method invoked by the command
<code>tie %hash, classname
</code>. Associates a new
102 hash instance with the specified class.
<code>LIST
</code> would represent additional
103 arguments (along the lines of
<a href=
"file://C|\msysgit\mingw\html/lib/AnyDBM_File.html">the AnyDBM_File manpage
</a> and compatriots) needed to
104 complete the association.
</p>
107 <dt><strong><a name=
"item_store_this_2c_key_2c_value">STORE this, key, value
</a></strong>
110 <p>Store datum
<em>value
</em> into
<em>key
</em> for the tied hash
<em>this
</em>.
</p>
113 <dt><strong><a name=
"item_fetch_this_2c_key">FETCH this, key
</a></strong>
116 <p>Retrieve the datum in
<em>key
</em> for the tied hash
<em>this
</em>.
</p>
119 <dt><strong><a name=
"item_firstkey_this">FIRSTKEY this
</a></strong>
122 <p>Return the first key in the hash.
</p>
125 <dt><strong><a name=
"item_nextkey_this_2c_lastkey">NEXTKEY this, lastkey
</a></strong>
128 <p>Return the next key in the hash.
</p>
131 <dt><strong><a name=
"item_exists_this_2c_key">EXISTS this, key
</a></strong>
134 <p>Verify that
<em>key
</em> exists with the tied hash
<em>this
</em>.
</p>
137 <p>The
<strong>Tie::Hash
</strong> implementation is a stub that simply croaks.
</p>
140 <dt><strong><a name=
"item_delete_this_2c_key">DELETE this, key
</a></strong>
143 <p>Delete the key
<em>key
</em> from the tied hash
<em>this
</em>.
</p>
146 <dt><strong><a name=
"item_clear_this">CLEAR this
</a></strong>
149 <p>Clear all values from the tied hash
<em>this
</em>.
</p>
152 <dt><strong><a name=
"item_scalar_this">SCALAR this
</a></strong>
155 <p>Returns what evaluating the hash in scalar context yields.
</p>
158 <p><strong>Tie::Hash
</strong> does not implement this method (but
<strong>Tie::StdHash
</strong>
159 and
<strong>Tie::ExtraHash
</strong> do).
</p>
166 <h1><a name=
"inheriting_from_tie__stdhash">Inheriting from
<strong>Tie::StdHash
</strong></a></h1>
167 <p>The accessor methods assume that the actual storage for the data in the tied
168 hash is in the hash referenced by
<code>tied(%tiedhash)
</code>. Thus overwritten
169 <code>TIEHASH
</code> method should return a hash reference, and the remaining methods
170 should operate on the hash referenced by the first argument:
</p>
173 our @ISA = 'Tie::StdHash';
</pre>
176 my $storage = bless {}, shift;
177 warn
"New ReportHash created, stored in $storage.\n
";
181 warn
"Storing data with key $_[
1] at $_[
0].\n
";
187 <h1><a name=
"inheriting_from_tie__extrahash">Inheriting from
<strong>Tie::ExtraHash
</strong></a></h1>
188 <p>The accessor methods assume that the actual storage for the data in the tied
189 hash is in the hash referenced by
<code>(tied(%tiedhash))-
>[
0]
</code>. Thus overwritten
190 <code>TIEHASH
</code> method should return an array reference with the first
191 element being a hash reference, and the remaining methods should operate on the
192 hash
<code>%{ $_[
0]-
>[
0] }
</code>:
</p>
195 our @ISA = 'Tie::ExtraHash';
</pre>
199 my $storage = bless [{}, @_], $class;
200 warn
"New ReportHash created, stored in $storage.\n
";
204 warn
"Storing data with key $_[
1] at $_[
0].\n
";
205 $_[
0][
0]{$_[
1]} = $_[
2]
207 <p>The default
<code>TIEHASH
</code> method stores ``extra'' arguments to
<code>tie()
</code> starting
208 from offset
1 in the array referenced by
<code>tied(%tiedhash)
</code>; this is the
209 same storage algorithm as in TIEHASH subroutine above. Hence, a typical
210 package inheriting from
<strong>Tie::ExtraHash
</strong> does not need to overwrite this
215 <h1><a name=
"scalar__untie_and_destroy"><code>SCALAR
</code>,
<code>UNTIE
</code> and
<code>DESTROY
</code></a></h1>
216 <p>The methods
<code>UNTIE
</code> and
<code>DESTROY
</code> are not defined in
<strong>Tie::Hash
</strong>,
217 <strong>Tie::StdHash
</strong>, or
<strong>Tie::ExtraHash
</strong>. Tied hashes do not require
218 presence of these methods, but if defined, the methods will be called in
219 proper time, see
<a href=
"file://C|\msysgit\mingw\html/pod/perltie.html">the perltie manpage
</a>.
</p>
220 <p><code>SCALAR
</code> is only defined in
<strong>Tie::StdHash
</strong> and
<strong>Tie::ExtraHash
</strong>.
</p>
221 <p>If needed, these methods should be defined by the package inheriting from
222 <strong>Tie::Hash
</strong>,
<strong>Tie::StdHash
</strong>, or
<strong>Tie::ExtraHash
</strong>. See
<em>pertie/``SCALAR''
</em>
223 to find out what happens when
<code>SCALAR
</code> does not exist.
</p>
227 <h1><a name=
"more_information">MORE INFORMATION
</a></h1>
228 <p>The packages relating to various DBM-related implementations (
<em>DB_File
</em>,
229 <em>NDBM_File
</em>, etc.) show examples of general tied hashes, as does the
230 <a href=
"file://C|\msysgit\mingw\html/lib/Config.html">the Config manpage
</a> module. While these do not utilize
<strong>Tie::Hash
</strong>, they serve as
231 good working examples.
</p>
232 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
233 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
234 <big><strong><span class=
"block"> Tie::ExtraHash - base class definitions for tied hashes
</span></strong></big>