Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Tie::Hash.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Tie::Hash 3"
132.TH Tie::Hash 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134Tie::Hash, Tie::StdHash, Tie::ExtraHash \- base class definitions for tied hashes
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& package NewHash;
139\& require Tie::Hash;
140.Ve
141.PP
142.Vb 1
143\& @ISA = (Tie::Hash);
144.Ve
145.PP
146.Vb 2
147\& sub DELETE { ... } # Provides needed method
148\& sub CLEAR { ... } # Overrides inherited method
149.Ve
150.PP
151.Vb 2
152\& package NewStdHash;
153\& require Tie::Hash;
154.Ve
155.PP
156.Vb 1
157\& @ISA = (Tie::StdHash);
158.Ve
159.PP
160.Vb 4
161\& # All methods provided by default, define only those needing overrides
162\& # Accessors access the storage in %{$_[0]};
163\& # TIEHASH should return a reference to the actual storage
164\& sub DELETE { ... }
165.Ve
166.PP
167.Vb 2
168\& package NewExtraHash;
169\& require Tie::Hash;
170.Ve
171.PP
172.Vb 1
173\& @ISA = (Tie::ExtraHash);
174.Ve
175.PP
176.Vb 8
177\& # All methods provided by default, define only those needing overrides
178\& # Accessors access the storage in %{$_[0][0]};
179\& # TIEHASH should return an array reference with the first element being
180\& # the reference to the actual storage
181\& sub DELETE {
182\& $_[0][1]->('del', $_[0][0], $_[1]); # Call the report writer
183\& delete $_[0][0]->{$_[1]}; # $_[0]->SUPER::DELETE($_[1])
184\& }
185.Ve
186.PP
187.Vb 1
188\& package main;
189.Ve
190.PP
191.Vb 4
192\& tie %new_hash, 'NewHash';
193\& tie %new_std_hash, 'NewStdHash';
194\& tie %new_extra_hash, 'NewExtraHash',
195\& sub {warn "Doing \eU$_[1]\eE of $_[2].\en"};
196.Ve
197.SH "DESCRIPTION"
198.IX Header "DESCRIPTION"
199This module provides some skeletal methods for hash-tying classes. See
200perltie for a list of the functions required in order to tie a hash
201to a package. The basic \fBTie::Hash\fR package provides a \f(CW\*(C`new\*(C'\fR method, as well
202as methods \f(CW\*(C`TIEHASH\*(C'\fR, \f(CW\*(C`EXISTS\*(C'\fR and \f(CW\*(C`CLEAR\*(C'\fR. The \fBTie::StdHash\fR and
203\&\fBTie::ExtraHash\fR packages
204provide most methods for hashes described in perltie (the exceptions
205are \f(CW\*(C`UNTIE\*(C'\fR and \f(CW\*(C`DESTROY\*(C'\fR). They cause tied hashes to behave exactly like standard hashes,
206and allow for selective overwriting of methods. \fBTie::Hash\fR grandfathers the
207\&\f(CW\*(C`new\*(C'\fR method: it is used if \f(CW\*(C`TIEHASH\*(C'\fR is not defined
208in the case a class forgets to include a \f(CW\*(C`TIEHASH\*(C'\fR method.
209.PP
210For developers wishing to write their own tied hashes, the required methods
211are briefly defined below. See the perltie section for more detailed
212descriptive, as well as example code:
213.IP "\s-1TIEHASH\s0 classname, \s-1LIST\s0" 4
214.IX Item "TIEHASH classname, LIST"
215The method invoked by the command \f(CW\*(C`tie %hash, classname\*(C'\fR. Associates a new
216hash instance with the specified class. \f(CW\*(C`LIST\*(C'\fR would represent additional
217arguments (along the lines of AnyDBM_File and compatriots) needed to
218complete the association.
219.IP "\s-1STORE\s0 this, key, value" 4
220.IX Item "STORE this, key, value"
221Store datum \fIvalue\fR into \fIkey\fR for the tied hash \fIthis\fR.
222.IP "\s-1FETCH\s0 this, key" 4
223.IX Item "FETCH this, key"
224Retrieve the datum in \fIkey\fR for the tied hash \fIthis\fR.
225.IP "\s-1FIRSTKEY\s0 this" 4
226.IX Item "FIRSTKEY this"
227Return the first key in the hash.
228.IP "\s-1NEXTKEY\s0 this, lastkey" 4
229.IX Item "NEXTKEY this, lastkey"
230Return the next key in the hash.
231.IP "\s-1EXISTS\s0 this, key" 4
232.IX Item "EXISTS this, key"
233Verify that \fIkey\fR exists with the tied hash \fIthis\fR.
234.Sp
235The \fBTie::Hash\fR implementation is a stub that simply croaks.
236.IP "\s-1DELETE\s0 this, key" 4
237.IX Item "DELETE this, key"
238Delete the key \fIkey\fR from the tied hash \fIthis\fR.
239.IP "\s-1CLEAR\s0 this" 4
240.IX Item "CLEAR this"
241Clear all values from the tied hash \fIthis\fR.
242.IP "\s-1SCALAR\s0 this" 4
243.IX Item "SCALAR this"
244Returns what evaluating the hash in scalar context yields.
245.Sp
246\&\fBTie::Hash\fR does not implement this method (but \fBTie::StdHash\fR
247and \fBTie::ExtraHash\fR do).
248.SH "Inheriting from \fBTie::StdHash\fP"
249.IX Header "Inheriting from Tie::StdHash"
250The accessor methods assume that the actual storage for the data in the tied
251hash is in the hash referenced by \f(CW\*(C`tied(%tiedhash)\*(C'\fR. Thus overwritten
252\&\f(CW\*(C`TIEHASH\*(C'\fR method should return a hash reference, and the remaining methods
253should operate on the hash referenced by the first argument:
254.PP
255.Vb 2
256\& package ReportHash;
257\& our @ISA = 'Tie::StdHash';
258.Ve
259.PP
260.Vb 9
261\& sub TIEHASH {
262\& my $storage = bless {}, shift;
263\& warn "New ReportHash created, stored in $storage.\en";
264\& $storage
265\& }
266\& sub STORE {
267\& warn "Storing data with key $_[1] at $_[0].\en";
268\& $_[0]{$_[1]} = $_[2]
269\& }
270.Ve
271.SH "Inheriting from \fBTie::ExtraHash\fP"
272.IX Header "Inheriting from Tie::ExtraHash"
273The accessor methods assume that the actual storage for the data in the tied
274hash is in the hash referenced by \f(CW\*(C`(tied(%tiedhash))\->[0]\*(C'\fR. Thus overwritten
275\&\f(CW\*(C`TIEHASH\*(C'\fR method should return an array reference with the first
276element being a hash reference, and the remaining methods should operate on the
277hash \f(CW\*(C`%{ $_[0]\->[0] }\*(C'\fR:
278.PP
279.Vb 2
280\& package ReportHash;
281\& our @ISA = 'Tie::ExtraHash';
282.Ve
283.PP
284.Vb 10
285\& sub TIEHASH {
286\& my $class = shift;
287\& my $storage = bless [{}, @_], $class;
288\& warn "New ReportHash created, stored in $storage.\en";
289\& $storage;
290\& }
291\& sub STORE {
292\& warn "Storing data with key $_[1] at $_[0].\en";
293\& $_[0][0]{$_[1]} = $_[2]
294\& }
295.Ve
296.PP
297The default \f(CW\*(C`TIEHASH\*(C'\fR method stores \*(L"extra\*(R" arguments to \fItie()\fR starting
298from offset 1 in the array referenced by \f(CW\*(C`tied(%tiedhash)\*(C'\fR; this is the
299same storage algorithm as in \s-1TIEHASH\s0 subroutine above. Hence, a typical
300package inheriting from \fBTie::ExtraHash\fR does not need to overwrite this
301method.
302.ie n .SH """SCALAR""\fP, \f(CW""UNTIE""\fP and \f(CW""DESTROY"""
303.el .SH "\f(CWSCALAR\fP, \f(CWUNTIE\fP and \f(CWDESTROY\fP"
304.IX Header "SCALAR, UNTIE and DESTROY"
305The methods \f(CW\*(C`UNTIE\*(C'\fR and \f(CW\*(C`DESTROY\*(C'\fR are not defined in \fBTie::Hash\fR,
306\&\fBTie::StdHash\fR, or \fBTie::ExtraHash\fR. Tied hashes do not require
307presence of these methods, but if defined, the methods will be called in
308proper time, see perltie.
309.PP
310\&\f(CW\*(C`SCALAR\*(C'\fR is only defined in \fBTie::StdHash\fR and \fBTie::ExtraHash\fR.
311.PP
312If needed, these methods should be defined by the package inheriting from
313\&\fBTie::Hash\fR, \fBTie::StdHash\fR, or \fBTie::ExtraHash\fR. See \*(L"\s-1SCALAR\s0\*(R" in pertie
314to find out what happens when \f(CW\*(C`SCALAR\*(C'\fR does not exist.
315.SH "MORE INFORMATION"
316.IX Header "MORE INFORMATION"
317The packages relating to various DBM-related implementations (\fIDB_File\fR,
318\&\fINDBM_File\fR, etc.) show examples of general tied hashes, as does the
319Config module. While these do not utilize \fBTie::Hash\fR, they serve as
320good working examples.