.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.14) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Time::Fake 3pm" .TH Time::Fake 3pm "2008-01-17" "perl v5.12.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Time::Fake \- Simulate different times without changing your system clock .SH "SYNOPSIS" .IX Header "SYNOPSIS" Pretend we are running 1 day in the future: .PP .Vb 1 \& use Time::Fake \*(Aq+1d\*(Aq; .Ve .PP Pretend we are running 1 year in the past: .PP .Vb 1 \& use Time::Fake \*(Aq\-1y\*(Aq; .Ve .PP Pretend the script started at epoch time 1234567: .PP .Vb 1 \& use Time::Fake 1234567; .Ve .PP See what an existing script would do if run 20 years in the future: .PP .Vb 1 \& % perl \-MTime::Fake="+20y" test.pl .Ve .PP Run a section of code in a time warp: .PP .Vb 1 \& use Time::Fake; \& \& # do some setup \& \& Time::Fake\->offset("+1y"); \& run_tests(); # thinks it\*(Aqs a year ahead \& \& Time::Fake\->reset; # back to the present .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Use this module to achieve the effect of changing your system clock, but without actually changing your system clock. It overrides the Perl builtin subs \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`localtime\*(C'\fR, and \f(CW\*(C`gmtime\*(C'\fR, causing them to return a \&\*(L"faked\*(R" time of your choice. From the script's point of view, time still flows at the normal rate, but it is just offset as if it were executing in the past or present. .PP You may find this module useful in writing test scripts for code that has time-sensitive logic. .SH "USAGE" .IX Header "USAGE" .SS "Using and importing:" .IX Subsection "Using and importing:" .Vb 1 \& use Time::Fake $t; .Ve .PP Is equivalent to: .PP .Vb 2 \& use Time::Fake; \& Time::Fake\->offset($t); .Ve .PP See below for arguments to \f(CW\*(C`offset\*(C'\fR. This usage makes it easy to fake the time for existing scripts, as in: .PP .Vb 1 \& % perl \-MTime::Fake=+1y script.pl .Ve .SS "offset" .IX Subsection "offset" .Vb 1 \& Time::Fake\->offset( [$t] ); .Ve .PP \&\f(CW$t\fR is either an epoch time, or a relative offset of the following form: .PP .Vb 4 \& +3 # 3 seconds in the future \& \-3s # 3 seconds in the past \& +1h # 1 hour in the future \& etc.. .Ve .PP Relative offsets must begin with a plus or minus symbol. The supported units are: .PP .Vb 6 \& s second \& m minute \& h hour \& d day (24 hours) \& M month (30 days) \& y year (365 days) .Ve .PP If \f(CW$t\fR is an epoch time, then \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`localtime\*(C'\fR, and \f(CW\*(C`gmtime\*(C'\fR will act as though the the current time (when \f(CW\*(C`offset\*(C'\fR was called) was actually at \f(CW$t\fR epoch seconds. Otherwise, the offset \f(CW$t\fR will be added to the times returned by these builtin subs. .PP When \f(CW$t\fR is false, \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`localtime\*(C'\fR, \f(CW\*(C`gmtime\*(C'\fR remain overridden, but their behavior resets to reflect the actual system time. .PP When \f(CW$t\fR is omitted, nothing is changed, but \f(CW\*(C`offset\*(C'\fR returns the current additive offset (in seconds). Otherwise, its return value is the \fIprevious\fR offset. .PP \&\f(CW\*(C`offset\*(C'\fR may be called several times. However, \fIThe effect of multiple calls is \s-1NOT\s0 \s-1CUMULATIVE\s0.\fR That is: .PP .Vb 2 \& Time::Fake\->offset("+1h"); \& Time::Fake\->offset("+1h"); \& \& ## same as \& # Time::Fake\->offset("+1h"); \& \& ## NOT the same as \& # Time::Fake\->offset("+2h"); .Ve .PP Each call to \f(CW\*(C`offset\*(C'\fR completely cancels out the effect of any previous calls. To make the effect cumulative, use the return value of calling \f(CW\*(C`offset\*(C'\fR with no arguments: .PP .Vb 3 \& Time::Fake\->offset("+1h"); \& ... \& Time::Fake\->offset( Time::Fake\->offset + 3600 ); # add another hour .Ve .SS "reset" .IX Subsection "reset" .Vb 1 \& Time::Fake\->reset; .Ve .PP Is the same as: .PP .Vb 1 \& Time::Fake\->offset(0); .Ve .PP That is, it returns all the affected builtin subs to their default behavior \*(-- reporing the actual system time. .SH "KNOWN CAVEATS" .IX Header "KNOWN CAVEATS" Time::Fake must be loaded at \f(CW\*(C`BEGIN\*(C'\fR\-time (e.g., with a standard \&\f(CW\*(C`use\*(C'\fR statement). It must be loaded before perl \fIcompiles\fR any code that uses \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`localtime\*(C'\fR, or \f(CW\*(C`gmtime\*(C'\fR. Due to inherent limitations in overriding builtin subs, any code that was compiled before loading Time::Fake will not be affected. .PP Because the system clock is not being changed, only Perl code that uses \f(CW\*(C`time\*(C'\fR, \f(CW\*(C`localtime\*(C'\fR, or \f(CW\*(C`gmtime\*(C'\fR will be fooled about the date. In particular, the operating system is not fooled, nor are other programs. If your Perl code modifies a file for example, the file's modification time will reflect the \fBactual\fR (not faked) time. Along the same lines, if your Perl script obtains the time from somewhere other than the affected builtins subs (e.g., \f(CW\*(C`qx/date/\*(C'\fR), the actual (not faked) time will be reflected. .PP Time::Fake doesn't affect \-M, \-A, \-C filetest operators in the way you'd probably want. These still report the \fBactual\fR (not faked) script start time minus file access time. .PP Time::Fake has not been tested with other modules that override the time builtins, e.g., Time::HiRes. .SH "SEE ALSO" .IX Header "SEE ALSO" Time::Warp, which uses \s-1XS\s0 to fool more of Perl. .SH "AUTHOR" .IX Header "AUTHOR" Time::Fake is written by Mike Rosulek . Feel free to contact me with comments, questions, patches, or whatever. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2008 Mike Rosulek. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.