Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / IPC::Run::Timer.3pm
1 .\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 'br\}
42 .\"
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
44 .ie \n(.g .ds Aq \(aq
45 .el       .ds Aq '
46 .\"
47 .\" If the F register is turned on, we'll generate index entries on stderr for
48 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49 .\" entries marked with X<> in POD.  Of course, you'll have to process the
50 .\" output yourself in some meaningful fashion.
51 .ie \nF \{\
52 .    de IX
53 .    tm Index:\\$1\t\\n%\t"\\$2"
54 ..
55 .    nr % 0
56 .    rr F
57 .\}
58 .el \{\
59 .    de IX
60 ..
61 .\}
62 .\"
63 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
65 .    \" fudge factors for nroff and troff
66 .if n \{\
67 .    ds #H 0
68 .    ds #V .8m
69 .    ds #F .3m
70 .    ds #[ \f1
71 .    ds #] \fP
72 .\}
73 .if t \{\
74 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
75 .    ds #V .6m
76 .    ds #F 0
77 .    ds #[ \&
78 .    ds #] \&
79 .\}
80 .    \" simple accents for nroff and troff
81 .if n \{\
82 .    ds ' \&
83 .    ds ` \&
84 .    ds ^ \&
85 .    ds , \&
86 .    ds ~ ~
87 .    ds /
88 .\}
89 .if t \{\
90 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
96 .\}
97 .    \" troff and (daisy-wheel) nroff accents
98 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105 .ds ae a\h'-(\w'a'u*4/10)'e
106 .ds Ae A\h'-(\w'A'u*4/10)'E
107 .    \" corrections for vroff
108 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110 .    \" for low resolution devices (crt and lpr)
111 .if \n(.H>23 .if \n(.V>19 \
112 \{\
113 .    ds : e
114 .    ds 8 ss
115 .    ds o a
116 .    ds d- d\h'-1'\(ga
117 .    ds D- D\h'-1'\(hy
118 .    ds th \o'bp'
119 .    ds Th \o'LP'
120 .    ds ae ae
121 .    ds Ae AE
122 .\}
123 .rm #[ #] #H #V #F C
124 .\" ========================================================================
125 .\"
126 .IX Title "IPC::Run::Timer 3"
127 .TH IPC::Run::Timer 3 "2009-07-13" "perl v5.8.7" "User Contributed Perl Documentation"
128 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
129 .\" way too many mistakes in technical documents.
130 .if n .ad l
131 .nh
132 .SH "NAME"
133 IPC::Run::Timer \-\- Timer channels for IPC::Run.
134 .SH "SYNOPSIS"
135 .IX Header "SYNOPSIS"
136 .Vb 3
137 \&   use IPC::Run qw( run  timer timeout );
138 \&   ## or IPC::Run::Timer ( timer timeout );
139 \&   ## or IPC::Run::Timer ( :all );
140 \&
141 \&   ## A non\-fatal timer:
142 \&   $t = timer( 5 ); # or...
143 \&   $t = IO::Run::Timer\->new( 5 );
144 \&   run $t, ...;
145 \&
146 \&   ## A timeout (which is a timer that dies on expiry):
147 \&   $t = timeout( 5 ); # or...
148 \&   $t = IO::Run::Timer\->new( 5, exception => "harness timed out" );
149 .Ve
150 .SH "DESCRIPTION"
151 .IX Header "DESCRIPTION"
152 This class and module allows timers and timeouts to be created for use
153 by IPC::Run.  A timer simply expires when it's time is up.  A timeout
154 is a timer that throws an exception when it expires.
155 .PP
156 Timeouts are usually a bit simpler to use  than timers: they throw an
157 exception on expiration so you don't need to check them:
158 .PP
159 .Vb 7
160 \&   ## Give @cmd 10 seconds to get started, then 5 seconds to respond
161 \&   my $t = timeout( 10 );
162 \&   $h = start(
163 \&      \e@cmd, \e$in, \e$out,
164 \&      $t,
165 \&   );
166 \&   pump $h until $out =~ /prompt/;
167 \&
168 \&   $in = "some stimulus";
169 \&   $out = \*(Aq\*(Aq;
170 \&   $t\->time( 5 )
171 \&   pump $h until $out =~ /expected response/;
172 .Ve
173 .PP
174 You do need to check timers:
175 .PP
176 .Vb 7
177 \&   ## Give @cmd 10 seconds to get started, then 5 seconds to respond
178 \&   my $t = timer( 10 );
179 \&   $h = start(
180 \&      \e@cmd, \e$in, \e$out,
181 \&      $t,
182 \&   );
183 \&   pump $h until $t\->is_expired || $out =~ /prompt/;
184 \&
185 \&   $in = "some stimulus";
186 \&   $out = \*(Aq\*(Aq;
187 \&   $t\->time( 5 )
188 \&   pump $h until $out =~ /expected response/ || $t\->is_expired;
189 .Ve
190 .PP
191 Timers and timeouts that are reset get started by \fIstart()\fR and
192 \&\fIpump()\fR.  Timers change state only in \fIpump()\fR.  Since \fIrun()\fR and
193 \&\fIfinish()\fR both call \fIpump()\fR, they act like \fIpump()\fR with repect to
194 timers.
195 .PP
196 Timers and timeouts have three states: reset, running, and expired.
197 Setting the timeout value resets the timer, as does calling
198 the \fIreset()\fR method.  The \fIstart()\fR method starts (or restarts) a
199 timer with the most recently set time value, no matter what state
200 it's in.
201 .SS "Time values"
202 .IX Subsection "Time values"
203 All time values are in seconds.  Times may be specified as integer or
204 floating point seconds, optionally preceded by puncuation-separated
205 days, hours, and minutes.\e
206 .PP
207 Examples:
208 .PP
209 .Vb 7
210 \&   1           1 second
211 \&   1.1         1.1 seconds
212 \&   60          60 seconds
213 \&   1:0         1 minute
214 \&   1:1         1 minute, 1 second
215 \&   1:90        2 minutes, 30 seconds
216 \&   1:2:3:4.5   1 day, 2 hours, 3 minutes, 4.5 seconds
217 .Ve
218 .PP
219 Absolute date/time strings are *not* accepted: year, month and
220 day-of-month parsing is not available (patches welcome :\-).
221 .SS "Interval fudging"
222 .IX Subsection "Interval fudging"
223 When calculating an end time from a start time and an interval, IPC::Run::Timer
224 instances add a little fudge factor.  This is to ensure that no time will
225 expire before the interval is up.
226 .PP
227 First a little background.  Time is sampled in discrete increments.  We'll
228 call the
229 exact moment that the reported time increments from one interval to the
230 next a tick, and the interval between ticks as the time period.  Here's
231 a diagram of three ticks and the periods between them:
232 .PP
233 .Vb 5
234 \&    \-0\-0\-0\-0\-0\-0\-0\-0\-0\-0\-1\-1\-1\-1\-1\-1\-1\-1\-1\-1\-2\-...
235 \&    ^                   ^                   ^
236 \&    |<\-\-\- period 0 \-\-\-\->|<\-\-\- period 1 \-\-\-\->|
237 \&    |                   |                   |
238 \&  tick 0              tick 1              tick 2
239 .Ve
240 .PP
241 To see why the fudge factor is necessary, consider what would happen
242 when a timer with an interval of 1 second is started right at the end of
243 period 0:
244 .PP
245 .Vb 7
246 \&    \-0\-0\-0\-0\-0\-0\-0\-0\-0\-0\-1\-1\-1\-1\-1\-1\-1\-1\-1\-1\-2\-...
247 \&    ^                ^  ^                   ^
248 \&    |                |  |                   |
249 \&    |                |  |                   |
250 \&  tick 0             |tick 1              tick 2
251 \&                     |
252 \&                 start $t
253 .Ve
254 .PP
255 Assuming that \fIcheck()\fR is called many times per period, then the timer
256 is likely to expire just after tick 1, since the time reported will have
257 lept from the value '0' to the value '1':
258 .PP
259 .Vb 9
260 \&    \-0\-0\-0\-0\-0\-0\-0\-0\-0\-0\-1\-1\-1\-1\-1\-1\-1\-1\-1\-1\-2\-...
261 \&    ^                ^  ^   ^               ^
262 \&    |                |  |   |               |
263 \&    |                |  |   |               |
264 \&  tick 0             |tick 1|             tick 2
265 \&                     |      |
266 \&                 start $t   |
267 \&                            |
268 \&                        check $t
269 .Ve
270 .PP
271 Adding a fudge of '1' in this example means that the timer is guaranteed
272 not to expire before tick 2.
273 .PP
274 The fudge is not added to an interval of '0'.
275 .PP
276 This means that intervals guarantee a minimum interval.  Given that
277 the process running perl may be suspended for some period of time, or that
278 it gets busy doing something time-consuming, there are no other guarantees on
279 how long it will take a timer to expire.
280 .SH "SUBCLASSING"
281 .IX Header "SUBCLASSING"
282 \&\s-1INCOMPATIBLE\s0 \s-1CHANGE:\s0 Due to the awkwardness introduced by ripping
283 pseudohashes out of Perl, this class \fIno longer\fR uses the fields
284 pragma.
285 .SH "FUNCTIONS & METHODS"
286 .IX Header "FUNCTIONS & METHODS"
287 .IP "timer" 4
288 .IX Item "timer"
289 A constructor function (not method) of IPC::Run::Timer instances:
290 .Sp
291 .Vb 2
292 \&   $t = timer( 5 );
293 \&   $t = timer( 5, name => \*(Aqstall timer\*(Aq, debug => 1 );
294 \&
295 \&   $t = timer;
296 \&   $t\->interval( 5 );
297 \&
298 \&   run ..., $t;
299 \&   run ..., $t = timer( 5 );
300 .Ve
301 .Sp
302 This convenience function is a shortened spelling of
303 .Sp
304 .Vb 1
305 \&   IPC::Run::Timer\->new( ... );
306 .Ve
307 .Sp
308 \&.  It returns a timer in the reset state with a given interval.
309 .Sp
310 If an exception is provided, it will be thrown when the timer notices that
311 it has expired (in \fIcheck()\fR).  The name is for debugging usage, if you plan on
312 having multiple timers around.  If no name is provided, a name like \*(L"timer #1\*(R"
313 will be provided.
314 .IP "timeout" 4
315 .IX Item "timeout"
316 A constructor function (not method) of IPC::Run::Timer instances:
317 .Sp
318 .Vb 3
319 \&   $t = timeout( 5 );
320 \&   $t = timeout( 5, exception => "kablooey" );
321 \&   $t = timeout( 5, name => "stall", exception => "kablooey" );
322 \&
323 \&   $t = timeout;
324 \&   $t\->interval( 5 );
325 \&
326 \&   run ..., $t;
327 \&   run ..., $t = timeout( 5 );
328 .Ve
329 .Sp
330 A This convenience function is a shortened spelling of
331 .Sp
332 .Vb 1
333 \&   IPC::Run::Timer\->new( exception => "IPC::Run: timeout ...", ... );
334 .Ve
335 .Sp
336 \&.  It returns a timer in the reset state that will throw an
337 exception when it expires.
338 .Sp
339 Takes the same parameters as \*(L"timer\*(R", any exception passed in overrides
340 the default exception.
341 .IP "new" 4
342 .IX Item "new"
343 .Vb 3
344 \&   IPC::Run::Timer\->new()  ;
345 \&   IPC::Run::Timer\->new( 5 )  ;
346 \&   IPC::Run::Timer\->new( 5, exception => \*(Aqkablooey\*(Aq )  ;
347 .Ve
348 .Sp
349 Constructor.  See \*(L"timer\*(R" for details.
350 .IP "check" 4
351 .IX Item "check"
352 .Vb 3
353 \&   check $t;
354 \&   check $t, $now;
355 \&   $t\->check;
356 .Ve
357 .Sp
358 Checks to see if a timer has expired since the last check.  Has no effect
359 on non-running timers.  This will throw an exception if one is defined.
360 .Sp
361 \&\fIIPC::Run::pump()\fR calls this routine for any timers in the harness.
362 .Sp
363 You may pass in a version of now, which is useful in case you have
364 it lying around or you want to check several timers with a consistent
365 concept of the current time.
366 .Sp
367 Returns the time left before end_time or 0 if end_time is no longer
368 in the future or the timer is not running
369 (unless, of course, \fIcheck()\fR \fIexpire()\fRs the timer and this
370 results in an exception being thrown).
371 .Sp
372 Returns undef if the timer is not running on entry, 0 if \fIcheck()\fR expires it,
373 and the time left if it's left running.
374 .IP "debug" 4
375 .IX Item "debug"
376 Sets/gets the current setting of the debugging flag for this timer.  This
377 has no effect if debugging is not enabled for the current harness.
378 .IP "end_time" 4
379 .IX Item "end_time"
380 .Vb 2
381 \&   $et = $t\->end_time;
382 \&   $et = end_time $t;
383 \&
384 \&   $t\->end_time( time + 10 );
385 .Ve
386 .Sp
387 Returns the time when this timer will or did expire.  Even if this time is
388 in the past, the timer may not be expired, since \fIcheck()\fR may not have been
389 called yet.
390 .Sp
391 Note that this end_time is not start_time($t) + interval($t), since some
392 small extra amount of time is added to make sure that the timer does not
393 expire before \fIinterval()\fR elapses.  If this were not so, then
394 .Sp
395 Changing \fIend_time()\fR while a timer is running will set the expiration time.
396 Changing it while it is expired has no affect, since \fIreset()\fRing a timer always
397 clears the \fIend_time()\fR.
398 .IP "exception" 4
399 .IX Item "exception"
400 .Vb 3
401 \&   $x = $t\->exception;
402 \&   $t\->exception( $x );
403 \&   $t\->exception( undef );
404 .Ve
405 .Sp
406 Sets/gets the exception to throw, if any.  'undef' means that no
407 exception will be thrown.  Exception does not need to be a scalar: you 
408 may ask that references be thrown.
409 .IP "interval" 4
410 .IX Item "interval"
411 .Vb 3
412 \&   $i = interval $t;
413 \&   $i = $t\->interval;
414 \&   $t\->interval( $i );
415 .Ve
416 .Sp
417 Sets the interval.  Sets the end time based on the \fIstart_time()\fR and the
418 interval (and a little fudge) if the timer is running.
419 .IP "expire" 4
420 .IX Item "expire"
421 .Vb 2
422 \&   expire $t;
423 \&   $t\->expire;
424 .Ve
425 .Sp
426 Sets the state to expired (undef).
427 Will throw an exception if one
428 is defined and the timer was not already expired.  You can expire a
429 reset timer without starting it.
430 .IP "is_running" 4
431 .IX Item "is_running"
432 .PD 0
433 .IP "is_reset" 4
434 .IX Item "is_reset"
435 .IP "is_expired" 4
436 .IX Item "is_expired"
437 .IP "name" 4
438 .IX Item "name"
439 .PD
440 Sets/gets this timer's name.  The name is only used for debugging
441 purposes so you can tell which freakin' timer is doing what.
442 .IP "reset" 4
443 .IX Item "reset"
444 .Vb 2
445 \&   reset $t;
446 \&   $t\->reset;
447 .Ve
448 .Sp
449 Resets the timer to the non-running, non-expired state and clears
450 the \fIend_time()\fR.
451 .IP "start" 4
452 .IX Item "start"
453 .Vb 4
454 \&   start $t;
455 \&   $t\->start;
456 \&   start $t, $interval;
457 \&   start $t, $interval, $now;
458 .Ve
459 .Sp
460 Starts or restarts a timer.  This always sets the start_time.  It sets the
461 end_time based on the interval if the timer is running or if no end time
462 has been set.
463 .Sp
464 You may pass an optional interval or current time value.
465 .Sp
466 Not passing a defined interval causes the previous interval setting to be
467 re-used unless the timer is reset and an end_time has been set
468 (an exception is thrown if no interval has been set).
469 .Sp
470 Not passing a defined current time value causes the current time to be used.
471 .Sp
472 Passing a current time value is useful if you happen to have a time value
473 lying around or if you want to make sure that several timers are started
474 with the same concept of start time.  You might even need to lie to an
475 IPC::Run::Timer, occasionally.
476 .IP "start_time" 4
477 .IX Item "start_time"
478 Sets/gets the start time, in seconds since the epoch.  Setting this manually
479 is a bad idea, it's better to call \*(L"start\*(R"() at the correct time.
480 .IP "state" 4
481 .IX Item "state"
482 .Vb 2
483 \&   $s = state $t;
484 \&   $t\->state( $s );
485 .Ve
486 .Sp
487 Get/Set the current state.  Only use this if you really need to transfer the
488 state to/from some variable.
489 Use \*(L"expire\*(R", \*(L"start\*(R", \*(L"reset\*(R", \*(L"is_expired\*(R", \*(L"is_running\*(R",
490 \&\*(L"is_reset\*(R".
491 .Sp
492 Note:  Setting the state to 'undef' to expire a timer will not throw an
493 exception.
494 .SH "TODO"
495 .IX Header "TODO"
496 use Time::HiRes; if it's present.
497 .PP
498 Add detection and parsing of [[[\s-1HH:\s0]MM:]SS formatted times and intervals.
499 .SH "AUTHOR"
500 .IX Header "AUTHOR"
501 Barrie Slaymaker <barries@slaysys.com>