Time::Mock(3pm)

πŸ“¦
version 0.0.2 Β· 4 versions
, in ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Time::Mock πŸ’–

okay bestie, so you know how you want to mess with the clock but like... inside Perl only? This is Time::Mock, straight out of the User Contributed Perl Documentation corner of CPAN, and it is literally a time machine in a module. Shift it, scale it, slay. πŸ•°οΈβœ¨


✨ NAME ✨

Time::Mock β€” shift and scale time πŸ’«


πŸŽ€ SYNOPSIS πŸŽ€

Speed up your sleep(), alarm(), and time() calls. no cap, it just does that.

use Time::Mock throttle => 100;
use Your::Code;

πŸ¦‹ ABOUT πŸ¦‹

ngl, Test::MockTime is nice and all, but she doesn't let you accelerate the timestep, she doesn't deal with Time::HiRes, and she gives you absolutely zero way to change the time across forks. it's giving limited. πŸ™ˆ

TODO: replace Time::HiRes functions with wrappers
TODO: finish the interfaces to real time/sleep/alarm

okay those are the author's to-dos, not mine, we're just reporting. iykyk. πŸ’…


🌈 Replaces

These core functions are replaced. πŸ‘‘

Eventually, much of the same bits from Time::HiRes will be correspondingly overwritten too.

  • time
  • localtime
  • gmtime
  • sleep β€” sleeps for 1/$throttle.
  • alarm β€” alarm happens in 1/$throttle.

πŸ’œ Class Methods

These are the knobs on your time machine πŸŽ›οΈ β€” but note that it is probably best to adjust them only once: see caveats. For convenience, import() takes will call these methods with each key in its argument list.

perl -MTime::Mock=throttle,600,set,"2009-11-01 00:59" dst_bug.pl

⭐ throttle

Get or set the throttle.

Time::Mock->throttle(10_000);

⭐ offset

Get or set the offset.

Time::Mock->offset(120);

⭐ set

Set the time to a given value. This may be a numeric time or anything parseable by Date::Parse::str2time() (you need to install Date::Parse to enable this.)

Time::Mock->set("2009-11-01 00:59");

🫢 Caveats

This package remembers the actual system time when it was loaded and makes adjustments from there. πŸ“Œ

Future versions might change this behavior if I can think of a good reason and scheme for that.

🧚 forks and threads

The throttle value will hold across forks, but there is no support for propagating changes to child processes. So, set the knobs only before you fork! 😀

Don't ask about threads unless you're asking about me applying your patch thanks.

πŸ“ Networking and System stuff

We're only lying about the clock inside of Perl, not magically messing with the universe. 🌌

πŸ’€ Time Travel is Dangerous

I suggest that you set the knobs at import() and don't mess with them after that unless you're well aware of how your code is using time.

Messing with the throttle during runtime could also give your code the illusion of time going backwards. 😭 If your code tries to do math with the return values of time() before and after a slow-down, there could be trouble.

Changing the throttle while an alarm() is set won't change the original alarm time. There would be a similar caveat about sleep() if I hadn't already mentioned forks ;-)

Finally, don't ever let your past self see your future self. πŸ‘€


πŸ‘‘ AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/


πŸ”₯ BUGS

If you found this module on CPAN, please report any bugs or feature requests through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. πŸ›

If you pulled this development version from my /svn/, please contact me directly.


Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.


πŸ’… NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned. 🫒


🌈 LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page bestie, we ate and left no crumbs πŸ’– this lil doc ships as perl v5.30.3, dated 2020-06-02, under the Time::Mock(3pm) banner β€” go shift some time, you main character. βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from