| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package uny2k; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
2
|
|
2
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
426
|
|
|
4
|
2
|
|
|
2
|
|
2
|
use warnings; |
|
|
2
|
|
|
|
|
41
|
|
|
|
2
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '19.108_0823'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2
|
use Carp; |
|
|
2
|
|
|
|
|
66
|
|
|
|
2
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2
|
|
|
|
|
1832
|
use overload '+' => \&add, |
|
11
|
|
|
|
|
|
|
'%' => \&mod, |
|
12
|
|
|
|
|
|
|
'' => \&stringize, |
|
13
|
|
|
|
|
|
|
'0+'=> \&numize, |
|
14
|
2
|
|
|
2
|
|
2
|
'fallback' => 'TRUE'; |
|
|
2
|
|
|
|
|
177
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
|
17
|
1
|
|
|
1
|
0
|
1
|
my $proto = shift; |
|
18
|
1
|
|
33
|
|
|
4
|
my $class = ref $proto || $proto; |
|
19
|
1
|
|
|
|
|
1
|
my($year, $reaction) = @_; |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
7
|
my $self = {}; |
|
22
|
1
|
|
|
|
|
1
|
$self->{_Year} = $year; |
|
23
|
1
|
|
50
|
|
|
2
|
$self->{_Reaction} = $reaction || 'die'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
3
|
return bless $self => $class; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub stringize { |
|
30
|
1
|
|
|
0
|
0
|
2
|
return shift->{_Year}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub numize { |
|
35
|
1
|
|
|
0
|
0
|
3
|
return shift->{_Year}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _mk_localtime { |
|
40
|
0
|
|
|
3
|
|
0
|
my($reaction) = shift; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return sub { |
|
43
|
3
|
0
|
|
1
|
|
3
|
return @_ ? localtime($_[0]) : localtime() unless wantarray; |
|
|
|
50
|
|
|
|
|
|
|
44
|
3
|
50
|
|
|
|
10
|
my @t = @_ ? localtime($_[0]) : localtime(); |
|
45
|
1
|
|
|
|
|
3
|
$t[5] = __PACKAGE__->new($t[5], $reaction); |
|
46
|
1
|
|
|
|
|
102
|
@t; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
0
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _mk_gmtime { |
|
51
|
1
|
|
|
3
|
|
5
|
my($reaction) = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return sub { |
|
54
|
3
|
0
|
|
0
|
|
5
|
return @_ ? gmtime($_[0]) : gmtime() unless wantarray; |
|
|
|
0
|
|
|
|
|
|
|
55
|
3
|
0
|
|
|
|
8
|
my @t = @_ ? gmtime($_[0]) : gmtime(); |
|
56
|
0
|
|
|
|
|
0
|
$t[5] = __PACKAGE__->new($t[5], $reaction); |
|
57
|
0
|
|
|
|
|
0
|
@t; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
1
|
|
|
|
|
3
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub import { |
|
63
|
1
|
|
|
3
|
|
401
|
() = shift; # Dump the package. |
|
|
0
|
|
|
|
|
0
|
|
|
64
|
0
|
|
|
|
|
0
|
my $reaction = shift; |
|
65
|
3
|
|
|
|
|
7
|
my $caller = caller; |
|
66
|
|
|
|
|
|
|
|
|
67
|
3
|
50
|
|
|
|
3
|
$reaction = ':DIE' unless defined $reaction; |
|
68
|
|
|
|
|
|
|
|
|
69
|
3
|
50
|
|
|
|
6
|
$reaction = $reaction eq ':WARN' ? 'warn' : 'die'; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
{ |
|
72
|
2
|
|
|
2
|
|
1591
|
no strict 'refs'; |
|
|
2
|
|
|
|
|
14
|
|
|
|
2
|
|
|
|
|
1371
|
|
|
|
3
|
|
|
|
|
10
|
|
|
73
|
3
|
|
|
|
|
8
|
*{$caller . '::localtime'} = _mk_localtime($reaction); |
|
|
3
|
|
|
|
|
1
|
|
|
74
|
3
|
|
|
|
|
7
|
*{$caller . '::gmtime'} = _mk_gmtime($reaction); |
|
|
3
|
|
|
|
|
28
|
|
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
15
|
return 1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add { |
|
81
|
3
|
|
|
1
|
0
|
15
|
my($self, $a2) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
3
|
50
|
|
|
|
1131
|
if( $a2 == 1900 ) { |
|
84
|
1
|
|
|
|
|
1
|
carp("Possible y2k fix found! Unfixing."); |
|
85
|
1
|
|
|
|
|
2
|
return "19" . $self->{_Year}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
else { |
|
88
|
1
|
|
|
|
|
120
|
return $self->{_Year} + $a2; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub mod { |
|
93
|
1
|
|
|
1
|
0
|
73
|
my($self, $modulus) = @_; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
50
|
|
|
|
0
|
if( $modulus == 100 ) { |
|
96
|
1
|
|
|
|
|
2
|
carp("Possible y2k fix found! Unfixing."); |
|
97
|
1
|
|
|
|
|
4
|
return $self->{_Year}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
else { |
|
100
|
1
|
|
|
|
|
81
|
return $self->{_Year} % $modulus; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub concat { |
|
105
|
1
|
|
|
0
|
0
|
36
|
my($self, $a2, $rev) = @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ($rev) { |
|
108
|
0
|
|
|
|
|
|
return $a2 . $self->{_Year}; |
|
109
|
|
|
|
|
|
|
} else { |
|
110
|
0
|
|
|
|
|
|
return $self->{_Year} . $a2; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $self->{_Year}; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 NAME |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
uny2k - Removes y2k fixes |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use uny2k; |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$year = (localtime)[5]; |
|
126
|
|
|
|
|
|
|
printf "In the year %d, computers will everything for us!\n", |
|
127
|
|
|
|
|
|
|
$year += 1900; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Y2K has come and gone and none of the predictions of Doom and Gloom |
|
132
|
|
|
|
|
|
|
came to past. As the crisis is over, you're probably wondering why |
|
133
|
|
|
|
|
|
|
you went through all that trouble to make sure your programs are "Y2K |
|
134
|
|
|
|
|
|
|
compliant". uny2k.pm is a simple module to remove the now unnecessary |
|
135
|
|
|
|
|
|
|
y2k fixes from your code. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Y2K was a special case of date handling, and we all know that special |
|
138
|
|
|
|
|
|
|
cases make programs more complicated and slower. Also, most Y2K fixes |
|
139
|
|
|
|
|
|
|
will fail around 2070 or 2090 (depending on how careful you were when |
|
140
|
|
|
|
|
|
|
writing the fix) so in order to avert a future crisis it would be best |
|
141
|
|
|
|
|
|
|
to remove the broken "fix" now. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
uny2k will remove the most common y2k fixes in Perl: |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=for example |
|
146
|
1
|
|
|
1
|
|
1
|
use uny2k; |
|
|
1
|
|
|
1
|
|
24
|
|
|
|
1
|
|
|
|
|
13546
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
443
|
|
|
|
1
|
|
|
|
|
74
|
|
|
147
|
0
|
|
|
|
|
0
|
my $year = (localtime)[5]; |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=also begin example |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
0
|
$full_year = $year + 1900; |
|
152
|
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
4
|
$two_digit_year = $year % 100; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=also end example |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
It will change them back to their proper post-y2k values, 19100 and |
|
158
|
|
|
|
|
|
|
100 respectively. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=for example_testing |
|
161
|
1
|
|
|
|
|
25
|
my $real_year = (CORE::localtime)[5]; |
|
162
|
1
|
|
|
|
|
5
|
is( $full_year, '19'.$real_year, "undid + 1900 fix" ); |
|
163
|
1
|
|
|
|
|
27
|
is( $two_digit_year, $real_year, "undid % 100 fix" ); |
|
164
|
|
|
|
|
|
|
|
|
165
|
1
|
|
|
|
|
9
|
|
|
166
|
1
|
|
|
|
|
181
|
=head1 AUTHOR |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Michael G Schwern |
|
169
|
1
|
|
|
|
|
171
|
with apologies to Mark "I am not ominous" Dominus for further abuse |
|
170
|
1
|
|
|
|
|
16
|
of his code. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 LICENSE and COPYRIGHT |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Copyright 2001-2008 Michael G Schwern Eschwern@pobox.comE. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
178
|
|
|
|
|
|
|
modify it under the same terms as Perl itself (though why you |
|
179
|
|
|
|
|
|
|
would want to is beyond me). |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
See F |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
y2k.pm, D'oh::Year, a good therapist |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
"Yes, this code is a joke."; |