1Time::Mock(3) User Contributed Perl Documentation Time::Mock(3)
2
3
4
6 Time::Mock - shift and scale time
7
9 Speed up your sleep(), alarm(), and time() calls.
10
11 use Time::Mock throttle => 100;
12 use Your::Code;
13
15 Test::MockTime is nice, but doesn't allow you to accelerate the
16 timestep and doesn't deal with Time::HiRes or give you any way to
17 change the time across forks.
18
19 TODO: replace Time::HiRes functions with wrappers
20
21 TODO: finish the interfaces to real time/sleep/alarm
22
24 These core functions are replaced.
25
26 Eventually, much of the same bits from Time::HiRes will be
27 correspondingly overwritten.
28
29 time
30 localtime
31 gmtime
32 sleep
33 Sleeps for 1/$throttle.
34
35 alarm
36 Alarm happens in 1/$throttle.
37
39 These are the knobs on your time machine, but note that it is probably
40 best to adjust them only once: see caveats. For convenience, import()
41 takes will call these methods with each key in its argument list.
42
43 perl -MTime::Mock=throttle,600,set,"2009-11-01 00:59" dst_bug.pl
44
45 throttle
46 Get or set the throttle.
47
48 Time::Mock->throttle(10_000);
49
50 offset
51 Get or set the offset.
52
53 Time::Mock->offset(120);
54
55 set
56 Set the time to a given value. This may be a numeric time or anything
57 parseable by Date::Parse::str2time() (you need to install Date::Parse
58 to enable this.)
59
60 Time::Mock->set("2009-11-01 00:59");
61
63 This package remembers the actual system time when it was loaded and
64 makes adjustments from there.
65
66 Future versions might change this behavior if I can think of a good
67 reason and scheme for that.
68
69 forks and threads
70 The throttle value will hold across forks, but there is no support for
71 propagating changes to child processes. So, set the knobs only before
72 you fork!
73
74 Don't ask about threads unless you're asking about me applying your
75 patch thanks.
76
77 Networking and System stuff
78 We're only lying about the clock inside of Perl, not magically messing
79 with the universe.
80
81 Time Travel is Dangerous
82 I suggest that you set the knobs at import() and don't mess with them
83 after that unless you're well aware of how your code is using time.
84
85 Messing with the throttle during runtime could also give your code the
86 illusion of time going backwards. If your code tries to do math with
87 the return values of time() before and after a slow-down, there could
88 be trouble.
89
90 Changing the throttle while an alarm() is set won't change the original
91 alarm time. There would be a similar caveat about sleep() if I hadn't
92 already mentioned forks ;-)
93
94 Finally, don't ever let your past self see your future self.
95
97 Eric Wilhelm @ <ewilhelm at cpan dot org>
98
99 http://scratchcomputing.com/
100
102 If you found this module on CPAN, please report any bugs or feature
103 requests through the web interface at <http://rt.cpan.org>. I will be
104 notified, and then you'll automatically be notified of progress on your
105 bug as I make changes.
106
107 If you pulled this development version from my /svn/, please contact me
108 directly.
109
111 Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.
112
114 Absolutely, positively NO WARRANTY, neither express or implied, is
115 offered with this software. You use this software at your own risk.
116 In case of loss, no person or entity owes you anything whatsoever. You
117 have been warned.
118
120 This program is free software; you can redistribute it and/or modify it
121 under the same terms as Perl itself.
122
123
124
125perl v5.28.1 2019-02-02 Time::Mock(3)