| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Time::Elapse; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.006; |
|
4
|
1
|
|
|
1
|
|
17001
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
6
|
1
|
|
|
1
|
|
1044
|
use autouse 'Carp' => qw(confess); |
|
|
1
|
|
|
|
|
882
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
1
|
|
|
1
|
|
993
|
use POSIX qw/ strftime /; |
|
|
1
|
|
|
|
|
8806
|
|
|
|
1
|
|
|
|
|
14
|
|
|
8
|
1
|
|
|
1
|
|
3160
|
use Time::HiRes qw/ gettimeofday /; |
|
|
1
|
|
|
|
|
2165
|
|
|
|
1
|
|
|
|
|
4
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# localtime and gmtime seem to be reversed |
|
11
|
|
|
|
|
|
|
# across different OS's (MacPerl, Darwin Perl, linux Perl) |
|
12
|
|
|
|
|
|
|
# perhaps my install of Perl is broken? setting local TZ to |
|
13
|
|
|
|
|
|
|
# UTC seems to resolve this but it *should not be necessary!* |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 1.24_02; |
|
16
|
|
|
|
|
|
|
our $_DEBUG = 0; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub TIESCALAR |
|
19
|
|
|
|
|
|
|
{ |
|
20
|
1
|
|
|
1
|
|
13
|
local $ENV{TZ} = 'UTC';# ridiculous! shouldn't be necessary. |
|
21
|
1
|
|
|
|
|
3
|
my( $class, $val ) = @_; |
|
22
|
1
|
50
|
|
|
|
6
|
$val = "" unless defined($val); |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
5
|
confess "Elapse->lapse() unable to use referenced values" |
|
25
|
|
|
|
|
|
|
if ref($val); |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
23
|
bless { now => [gettimeofday()], val => $val }, $class; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub FETCH |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
3
|
|
|
3
|
|
3001412
|
local $ENV{TZ} = 'UTC';# ridiculous! shouldn't be necessary. |
|
33
|
3
|
|
|
|
|
10
|
my ( $impl, $val ) = @_; |
|
34
|
3
|
|
|
|
|
17
|
my ($time, $ms) = gettimeofday(); |
|
35
|
|
|
|
|
|
|
|
|
36
|
3
|
50
|
|
|
|
24
|
print "(\$time = $time, \$ms = $ms)\n" |
|
37
|
|
|
|
|
|
|
if $_DEBUG; |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
50
|
|
|
|
26
|
if ( $ms < $impl->{now}[1] ) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
|
|
0
|
$time--; |
|
42
|
0
|
|
|
|
|
0
|
$ms += 1000000; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
3
|
50
|
|
|
|
76
|
print "changed? (\$time = $time, \$ms = $ms) [ $impl->{now}[1] ]\n" |
|
46
|
|
|
|
|
|
|
if $_DEBUG; |
|
47
|
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
22
|
my $float = sprintf("%06d", $ms - $impl->{now}[1]); |
|
49
|
3
|
50
|
|
|
|
10
|
print "Float = $float\n" |
|
50
|
|
|
|
|
|
|
if $_DEBUG; |
|
51
|
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
434
|
my $int = strftime( "%H:%M:%S", localtime( $time - $impl->{now}[0] ) ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
3
|
50
|
|
|
|
13
|
print <<"EOF" if $_DEBUG; |
|
55
|
0
|
|
|
|
|
0
|
# int = $int |
|
56
|
|
|
|
|
|
|
# Time = $time |
|
57
|
|
|
|
|
|
|
# IMPL = $impl->{now}[0] |
|
58
|
0
|
|
|
|
|
0
|
# Time - IMPL = @{[ $time - $impl->{now}[0] ]} |
|
59
|
|
|
|
|
|
|
# localtime = @{[ localtime($time - $impl->{now}[0]) ]} |
|
60
|
|
|
|
|
|
|
EOF |
|
61
|
|
|
|
|
|
|
|
|
62
|
3
|
50
|
|
|
|
20
|
$val = $impl->{val} eq "" ? "" : " [$impl->{val}]"; |
|
63
|
|
|
|
|
|
|
|
|
64
|
3
|
|
|
|
|
34
|
return "$int.$float" . $val; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub STORE |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
1
|
|
|
1
|
|
1251
|
local $ENV{TZ} = 'UTC';# ridiculous! shouldn't be necessary. |
|
70
|
1
|
|
|
|
|
3
|
my($impl, $val) = @_; |
|
71
|
1
|
50
|
|
|
|
4
|
$val = "" unless defined($val); |
|
72
|
|
|
|
|
|
|
|
|
73
|
1
|
50
|
|
|
|
3
|
confess "Elapse->lapse() unable to use referenced values" |
|
74
|
|
|
|
|
|
|
if ref($val); |
|
75
|
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
6
|
$impl->{now} = [gettimeofday()]; |
|
77
|
1
|
|
|
|
|
6
|
$impl->{val} = $val; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lapse |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
1
|
|
|
1
|
0
|
958
|
tie $_[1], $_[0], $_[1]; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |