/usr/share/perl5/Test/Time.pm is in libtest-time-perl 0.05-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | package Test::Time;
use strict;
use warnings;
use Test::More;
our $VERSION = '0.05';
our $time = CORE::time();
my $pkg = __PACKAGE__;
my $in_effect = 1;
sub in_effect {
$in_effect;
}
sub import {
my ($class, %opts) = @_;
$time = $opts{time} if defined $opts{time};
*CORE::GLOBAL::time = sub() {
if (in_effect) {
$time;
} else {
CORE::time();
}
};
*CORE::GLOBAL::sleep = sub(;$) {
if (in_effect) {
my $sleep = shift || 1;
$time += $sleep;
note "sleep $sleep";
} else {
CORE::sleep(shift);
}
}
};
sub unimport {
$in_effect = 0;
}
1;
__END__
=encoding utf8
=head1 NAME
Test::Time - Overrides the time() and sleep() core functions for testing
=head1 SYNOPSIS
use Test::Time;
# Freeze time
my $now = time();
# Increment internal time (returns immediately)
sleep 1;
# Return internal time incremented by 1
my $then = time();
=head1 DESCRIPTION
Test::Time can be used to test modules that deal with time. Once you C<use> this
module, all references to C<time> and C<sleep> will be internalized. You can set
custom time by passing time => number after the C<use> statement:
use Test::Time time => 1;
my $now = time; # $now is equal to 1
sleep 300; # returns immediately, displaying a note
my $then = time; # $then equals to 301
=head1 AUTHOR
cho45 E<lt>cho45@lowreal.netE<gt>
=head1 SEE ALSO
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|