line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Scalar::Epoch; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
87142
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base qw(Tie::Scalar); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
5447
|
|
7
|
1
|
|
|
1
|
|
2058
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
57
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
197
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub TIESCALAR { |
13
|
1
|
|
|
1
|
|
11
|
my $class = shift; |
14
|
1
|
|
50
|
|
|
7
|
my $options = shift || {}; |
15
|
1
|
|
|
|
|
4
|
return bless $options, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub STORE { |
19
|
2
|
|
|
2
|
|
1473
|
my $self = shift; |
20
|
|
|
|
|
|
|
# die unless asked not to (by having no_die in the tie statement) |
21
|
2
|
100
|
|
|
|
228
|
croak "Can't store to a Tie::Scalar::Epoch variable" unless $self->{no_die}; |
22
|
1
|
50
|
|
|
|
8
|
carp "Can't store to a Tie::Scalar::Epoch variable" if $^W; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub FETCH { |
26
|
2
|
|
|
2
|
|
1000956
|
my $self = shift; |
27
|
2
|
|
|
|
|
15
|
return time; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# module return |
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Tie::Scalar::Epoch - Create a scalar that always returns the number |
36
|
|
|
|
|
|
|
of non-leap seconds since whatever time the system considers to be the epoch. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# create a variable and tie |
41
|
|
|
|
|
|
|
tie my $epoch, 'Tie::Scalar::Epoch'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
print "$epoch\n"; # eg. 1351113480 |
44
|
|
|
|
|
|
|
sleep 2; # wait 2 seconds... |
45
|
|
|
|
|
|
|
print "$epoch\n"; # ... 1351113482 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# this will die; $epoch is a readonly variable |
48
|
|
|
|
|
|
|
$epoch = '2012'; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# don't die if no_die is true |
51
|
|
|
|
|
|
|
tie my $epoch, 'Tie::Scalar::Epoch', { no_die => 1 }; |
52
|
|
|
|
|
|
|
$epoch = '2012'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This is a B simple class that creates readonly scalars |
58
|
|
|
|
|
|
|
that always return the current epoch. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A variables tied to this class is readonly, and attempting to |
61
|
|
|
|
|
|
|
assign to it will raise an exception. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 OPTIONS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The following options can be passed in a hashref to C. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item C |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Do not throw an exception when attempting to assign to a |
72
|
|
|
|
|
|
|
tied scalar. This module will still emit a warning if you |
73
|
|
|
|
|
|
|
have warnings enabled. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L, L, |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Victor Houston, C<< >> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Copyright E2012 by Victor Houston.
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
90
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |