Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | .\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13 |
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::Watch 3" | |
132 | .TH Tie::Watch 3 "2000-12-30" "Tk800.023" "perl/Tk Documentation" | |
133 | .SH "NAME" | |
134 | .Vb 1 | |
135 | \& Tie::Watch - place watchpoints on Perl variables. | |
136 | .Ve | |
137 | .SH "SYNOPSIS" | |
138 | .IX Header "SYNOPSIS" | |
139 | .Vb 1 | |
140 | \& use Tie::Watch; | |
141 | .Ve | |
142 | .PP | |
143 | .Vb 14 | |
144 | \& $watch = Tie::Watch->new( | |
145 | \& -variable => \e$frog, | |
146 | \& -debug => 1, | |
147 | \& -shadow => 0, | |
148 | \& -fetch => [\e&fetch, 'arg1', 'arg2', ..., 'argn'], | |
149 | \& -store => \e&store, | |
150 | \& -destroy => sub {print "Final value=$frog.\en"}, | |
151 | \& } | |
152 | \& %vinfo = $watch->Info; | |
153 | \& $args = $watch->Args(-fetch); | |
154 | \& $val = $watch->Fetch; | |
155 | \& print "val=", $watch->Say($val), ".\en"; | |
156 | \& $watch->Store('Hello'); | |
157 | \& $watch->Unwatch; | |
158 | .Ve | |
159 | .SH "DESCRIPTION" | |
160 | .IX Header "DESCRIPTION" | |
161 | This class module binds one or more subroutines of your devising to a | |
162 | Perl variable. All variables can have \fB\s-1FETCH\s0\fR, \fB\s-1STORE\s0\fR and | |
163 | \&\fB\s-1DESTROY\s0\fR callbacks. Additionally, arrays can define \fB\s-1CLEAR\s0\fR, \fB\s-1EXTEND\s0\fR, | |
164 | \&\fB\s-1FETCHSIZE\s0\fR, \fB\s-1POP\s0\fR, \fB\s-1PUSH\s0\fR, \fB\s-1SHIFT\s0\fR, \fB\s-1SPLICE\s0\fR, \fB\s-1STORESIZE\s0\fR and | |
165 | \&\fB\s-1UNSHIFT\s0\fR callbacks, and hashes can define \fB\s-1CLEAR\s0\fR, \fB\s-1DELETE\s0\fR, \fB\s-1EXISTS\s0\fR, | |
166 | \&\fB\s-1FIRSTKEY\s0\fR and \fB\s-1NEXTKEY\s0\fR callbacks. If these term are unfamiliar to you, | |
167 | I \fIreally\fR suggest you read perltie. | |
168 | .PP | |
169 | With Tie::Watch you can: | |
170 | .PP | |
171 | .Vb 4 | |
172 | \& . alter a variable's value | |
173 | \& . prevent a variable's value from being changed | |
174 | \& . invoke a Perl/Tk callback when a variable changes | |
175 | \& . trace references to a variable | |
176 | .Ve | |
177 | .PP | |
178 | Callback format is patterned after the Perl/Tk scheme: supply either a | |
179 | code reference, or, supply an array reference and pass the callback | |
180 | code reference in the first element of the array, followed by callback | |
181 | arguments. (See examples in the Synopsis, above.) | |
182 | .PP | |
183 | Tie::Watch provides default callbacks for any that you fail to | |
184 | specify. Other than negatively impacting performance, they perform | |
185 | the standard action that you'd expect, so the variable behaves | |
186 | \&\*(L"normally\*(R". Once you override a default callback, perhaps to insert | |
187 | debug code like print statements, your callback normally finishes by | |
188 | calling the underlying (overridden) method. But you don't have to! | |
189 | .PP | |
190 | To map a tied method name to a default callback name simply lowercase | |
191 | the tied method name and uppercase its first character. So \s-1FETCH\s0 | |
192 | becomes Fetch, \s-1NEXTKEY\s0 becomes Nextkey, etcetera. | |
193 | .PP | |
194 | Here are two callbacks for a scalar. The \fB\s-1FETCH\s0\fR (read) callback does | |
195 | nothing other than illustrate the fact that it returns the value to | |
196 | assign the variable. The \fB\s-1STORE\s0\fR (write) callback uppercases the | |
197 | variable and returns it. In all cases the callback \fImust\fR return the | |
198 | correct read or write value \- typically, it does this by invoking the | |
199 | underlying method. | |
200 | .PP | |
201 | .Vb 4 | |
202 | \& my $fetch_scalar = sub { | |
203 | \& my($self) = @_; | |
204 | \& $self->Fetch; | |
205 | \& }; | |
206 | .Ve | |
207 | .PP | |
208 | .Vb 4 | |
209 | \& my $store_scalar = sub { | |
210 | \& my($self, $new_val) = @_; | |
211 | \& $self->Store(uc $new_val); | |
212 | \& }; | |
213 | .Ve | |
214 | .PP | |
215 | Here are \fB\s-1FETCH\s0\fR and \fB\s-1STORE\s0\fR callbacks for either an array or hash. | |
216 | They do essentially the same thing as the scalar callbacks, but | |
217 | provide a little more information. | |
218 | .PP | |
219 | .Vb 9 | |
220 | \& my $fetch = sub { | |
221 | \& my($self, $key) = @_; | |
222 | \& my $val = $self->Fetch($key); | |
223 | \& print "In fetch callback, key=$key, val=", $self->Say($val); | |
224 | \& my $args = $self->Args(-fetch); | |
225 | \& print ", args=('", join("', '", @$args), "')" if $args; | |
226 | \& print ".\en"; | |
227 | \& $val; | |
228 | \& }; | |
229 | .Ve | |
230 | .PP | |
231 | .Vb 12 | |
232 | \& my $store = sub { | |
233 | \& my($self, $key, $new_val) = @_; | |
234 | \& my $val = $self->Fetch($key); | |
235 | \& $new_val = uc $new_val; | |
236 | \& $self->Store($key, $new_val); | |
237 | \& print "In store callback, key=$key, val=", $self->Say($val), | |
238 | \& ", new_val=", $self->Say($new_val); | |
239 | \& my $args = $self->Args(-store); | |
240 | \& print ", args=('", join("', '", @$args), "')" if $args; | |
241 | \& print ".\en"; | |
242 | \& $new_val; | |
243 | \& }; | |
244 | .Ve | |
245 | .PP | |
246 | In all cases, the first parameter is a reference to the Watch object, | |
247 | used to invoke the following class methods. | |
248 | .SH "METHODS" | |
249 | .IX Header "METHODS" | |
250 | .IP "$watch = Tie::Watch\->new(\-options => values);" 4 | |
251 | .IX Item "$watch = Tie::Watch->new(-options => values);" | |
252 | The watchpoint constructor method that accepts option/value pairs to | |
253 | create and configure the Watch object. The only required option is | |
254 | \&\fB\-variable\fR. | |
255 | .Sp | |
256 | \&\fB\-variable\fR is a \fIreference\fR to a scalar, array or hash variable. | |
257 | .Sp | |
258 | \&\fB\-debug\fR (default 0) is 1 to activate debug print statements internal | |
259 | to Tie::Watch. | |
260 | .Sp | |
261 | \&\fB\-shadow\fR (default 1) is 0 to disable array and hash shadowing. To | |
262 | prevent infinite recursion Tie::Watch maintains parallel variables for | |
263 | arrays and hashes. When the watchpoint is created the parallel shadow | |
264 | variable is initialized with the watched variable's contents, and when | |
265 | the watchpoint is deleted the shadow variable is copied to the original | |
266 | variable. Thus, changes made during the watch process are not lost. | |
267 | Shadowing is on my default. If you disable shadowing any changes made | |
268 | to an array or hash are lost when the watchpoint is deleted. | |
269 | .Sp | |
270 | Specify any of the following relevant callback parameters, in the | |
271 | format described above: \fB\-fetch\fR, \fB\-store\fR, \fB\-destroy\fR. | |
272 | Additionally for arrays: \fB\-clear\fR, \fB\-extend\fR, \fB\-fetchsize\fR, | |
273 | \&\fB\-pop\fR, \fB\-push\fR, \fB\-shift\fR, \fB\-splice\fR, \fB\-storesize\fR and | |
274 | \&\fB\-unshift\fR. Additionally for hashes: \fB\-clear\fR, \fB\-delete\fR, | |
275 | \&\fB\-exists\fR, \fB\-firstkey\fR and \fB\-nextkey\fR. | |
276 | .ie n .IP "$args = $watch\->Args(\-fetch);" 4 | |
277 | .el .IP "$args = \f(CW$watch\fR\->Args(\-fetch);" 4 | |
278 | .IX Item "$args = $watch->Args(-fetch);" | |
279 | Returns a reference to a list of arguments for the specified callback, | |
280 | or undefined if none. | |
281 | .ie n .IP "$watch\->\fIFetch()\fR; $watch\->Fetch($key);" 4 | |
282 | .el .IP "$watch\->\fIFetch()\fR; \f(CW$watch\fR\->Fetch($key);" 4 | |
283 | .IX Item "$watch->Fetch(); $watch->Fetch($key);" | |
284 | Returns a variable's current value. \f(CW$key\fR is required for an array or | |
285 | hash. | |
286 | .ie n .IP "%vinfo = $watch\fR\->\fIInfo();" 4 | |
287 | .el .IP "%vinfo = \f(CW$watch\fR\->\fIInfo()\fR;" 4 | |
288 | .IX Item "%vinfo = $watch->Info();" | |
289 | Returns a hash detailing the internals of the Watch object, with these | |
290 | keys: | |
291 | .Sp | |
292 | .Vb 10 | |
293 | \& %vinfo = { | |
294 | \& -variable => SCALAR(0x200737f8) | |
295 | \& -debug => '0' | |
296 | \& -shadow => '1' | |
297 | \& -value => 'HELLO SCALAR' | |
298 | \& -destroy => ARRAY(0x200f86cc) | |
299 | \& -fetch => ARRAY(0x200f8558) | |
300 | \& -store => ARRAY(0x200f85a0) | |
301 | \& -legible => above data formatted as a list of string, for printing | |
302 | \& } | |
303 | .Ve | |
304 | .Sp | |
305 | For array and hash Watch objects, the \fB\-value\fR key is replaced with a | |
306 | \&\fB\-ptr\fR key which is a reference to the parallel array or hash. | |
307 | Additionally, for an array or hash, there are key/value pairs for | |
308 | all the variable specific callbacks. | |
309 | .IP "$watch\->Say($val);" 4 | |
310 | .IX Item "$watch->Say($val);" | |
311 | Used mainly for debugging, it returns \f(CW$val\fR in quotes if required, or | |
312 | the string \*(L"undefined\*(R" for undefined values. | |
313 | .ie n .IP "$watch\->Store($new_val); $watch\fR\->Store($key, \f(CW$new_val);" 4 | |
314 | .el .IP "$watch\->Store($new_val); \f(CW$watch\fR\->Store($key, \f(CW$new_val\fR);" 4 | |
315 | .IX Item "$watch->Store($new_val); $watch->Store($key, $new_val);" | |
316 | Store a variable's new value. \f(CW$key\fR is required for an array or hash. | |
317 | .IP "$watch\->\fIUnwatch()\fR;" 4 | |
318 | .IX Item "$watch->Unwatch();" | |
319 | Stop watching the variable. | |
320 | .SH "EFFICIENCY CONSIDERATIONS" | |
321 | .IX Header "EFFICIENCY CONSIDERATIONS" | |
322 | If you can live using the class methods provided, please do so. You | |
323 | can meddle with the object hash directly and improved watch | |
324 | performance, at the risk of your code breaking in the future. | |
325 | .SH "AUTHOR" | |
326 | .IX Header "AUTHOR" | |
327 | Stephen.O.Lidie@Lehigh.EDU | |
328 | .SH "HISTORY" | |
329 | .IX Header "HISTORY" | |
330 | .Vb 3 | |
331 | \& lusol@Lehigh.EDU, LUCC, 96/05/30 | |
332 | \& . Original version 0.92 release, based on the Trace module from Hans Mulder, | |
333 | \& and ideas from Tim Bunce. | |
334 | .Ve | |
335 | .PP | |
336 | .Vb 2 | |
337 | \& lusol@Lehigh.EDU, LUCC, 96/12/25 | |
338 | \& . Version 0.96, release two inner references detected by Perl 5.004. | |
339 | .Ve | |
340 | .PP | |
341 | .Vb 3 | |
342 | \& lusol@Lehigh.EDU, LUCC, 97/01/11 | |
343 | \& . Version 0.97, fix Makefile.PL and MANIFEST (thanks Andreas Koenig). | |
344 | \& Make sure test.pl doesn't fail if Tk isn't installed. | |
345 | .Ve | |
346 | .PP | |
347 | .Vb 2 | |
348 | \& Stephen.O.Lidie@Lehigh.EDU, Lehigh University Computing Center, 97/10/03 | |
349 | \& . Version 0.98, implement -shadow option for arrays and hashes. | |
350 | .Ve | |
351 | .PP | |
352 | .Vb 6 | |
353 | \& Stephen.O.Lidie@Lehigh.EDU, Lehigh University Computing Center, 98/02/11 | |
354 | \& . Version 0.99, finally, with Perl 5.004_57, we can completely watch arrays. | |
355 | \& With tied array support this module is essentially complete, so its been | |
356 | \& optimized for speed at the expense of clarity - sorry about that. The | |
357 | \& Delete() method has been renamed Unwatch() because it conflicts with the | |
358 | \& builtin delete(). | |
359 | .Ve | |
360 | .PP | |
361 | .Vb 3 | |
362 | \& Stephen.O.Lidie@Lehigh.EDU, Lehigh University Computing Center, 99/04/04 | |
363 | \& . Version 1.0, for Perl 5.005_03, update Makefile.PL for ActiveState, and | |
364 | \& add two examples (one for Perl/Tk). | |
365 | .Ve | |
366 | .SH "COPYRIGHT" | |
367 | .IX Header "COPYRIGHT" | |
368 | Copyright (C) 1996 \- 1999 Stephen O. Lidie. All rights reserved. | |
369 | .PP | |
370 | This program is free software; you can redistribute it and/or modify it under | |
371 | the same terms as Perl itself. |