| 1 | package uny2k; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | our $VERSION = '19.108_0823'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | use overload '+' => \&add, | |||||||||||||||||||
| 11 | '%' => \&mod, | ||||||||||||||||||||
| 12 | '' => \&stringize, | ||||||||||||||||||||
| 13 | '0+'=> \&numize, | ||||||||||||||||||||
| 14 | 1 | ▶ | 'fallback' => 'TRUE'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub new { | ||||||||||||||||||||
| 17 | 0 | ▶ | my $proto = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 18 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 19 | 0 | my($year, $reaction) = @_; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | my $self = {}; | |||||||||||||||||||
| 22 | 0 | $self->{_Year} = $year; | |||||||||||||||||||
| 23 | 0 | ▶ | $self->{_Reaction} = $reaction || 'die'; | ||||||||||||||||||
|
Condition0%0/2
$reaction || 'die'
MC/DC0%0/1
$reaction || 'die'
$reaction
Truth table0%0/2
A
A= $reaction
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | return bless $self => $class; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | sub stringize { | ||||||||||||||||||||
| 30 | 0 | ▶ | return shift->{_Year}; | ||||||||||||||||||
|
Subroutine
stringize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub numize { | ||||||||||||||||||||
| 35 | 0 | ▶ | return shift->{_Year}; | ||||||||||||||||||
|
Subroutine
numize: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub _mk_localtime { | ||||||||||||||||||||
| 40 | 1 | ▶ | my($reaction) = shift; | ||||||||||||||||||
|
Subroutine
_mk_localtime: called CC=1 SCAR=4.6
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | return sub { | ||||||||||||||||||||
| 43 | 0 | ▶ | return @_ ? localtime($_[0]) : localtime() unless wantarray; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
| |||||||||||||||||||||
| 44 | 0 | ▶ | my @t = @_ ? localtime($_[0]) : localtime(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | $t[5] = __PACKAGE__->new($t[5], $reaction); | |||||||||||||||||||
| 46 | 0 | @t; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 1 | } | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub _mk_gmtime { | ||||||||||||||||||||
| 51 | 1 | ▶ | my($reaction) = shift; | ||||||||||||||||||
|
Subroutine
_mk_gmtime: called CC=1 SCAR=4.6
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | return sub { | ||||||||||||||||||||
| 54 | 0 | ▶ | return @_ ? gmtime($_[0]) : gmtime() unless wantarray; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
| |||||||||||||||||||||
| 55 | 0 | ▶ | my @t = @_ ? gmtime($_[0]) : gmtime(); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | $t[5] = __PACKAGE__->new($t[5], $reaction); | |||||||||||||||||||
| 57 | 0 | @t; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 1 | } | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | sub import { | ||||||||||||||||||||
| 63 | 1 | ▶ | () = shift; # Dump the package. | ||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 64 | 1 | my $reaction = shift; | |||||||||||||||||||
| 65 | 1 | my $caller = caller; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | ▶ | $reaction = ':DIE' unless defined $reaction; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | ▶ | $reaction = $reaction eq ':WARN' ? 'warn' : 'die'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | { | ||||||||||||||||||||
| 72 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 73 | 1 | *{$caller . '::localtime'} = _mk_localtime($reaction); | |||||||||||||||||||
| 74 | 1 | *{$caller . '::gmtime'} = _mk_gmtime($reaction); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | return 1; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | sub add { | ||||||||||||||||||||
| 81 | 0 | ▶ | my($self, $a2) = @_; | ||||||||||||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | if( $a2 == 1900 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | carp("Possible y2k fix found! Unfixing."); | |||||||||||||||||||
| 85 | 0 | return "19" . $self->{_Year}; | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||
| 88 | 0 | return $self->{_Year} + $a2; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | sub mod { | ||||||||||||||||||||
| 93 | 0 | ▶ | my($self, $modulus) = @_; | ||||||||||||||||||
|
Subroutine
mod: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | if( $modulus == 100 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | carp("Possible y2k fix found! Unfixing."); | |||||||||||||||||||
| 97 | 0 | return $self->{_Year}; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||
| 100 | 0 | return $self->{_Year} % $modulus; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | sub concat { | ||||||||||||||||||||
| 105 | 0 | ▶ | my($self, $a2, $rev) = @_; | ||||||||||||||||||
|
Subroutine
concat: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 0 | ▶ | if ($rev) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | use uny2k; | ||||||||||||||||||||
| 147 | my $year = (localtime)[5]; | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =also begin example | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | $full_year = $year + 1900; | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | $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 | my $real_year = (CORE::localtime)[5]; | ||||||||||||||||||||
| 162 | is( $full_year, '19'.$real_year, "undid + 1900 fix" ); | ||||||||||||||||||||
| 163 | is( $two_digit_year, $real_year, "undid % 100 fix" ); | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head1 AUTHOR | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | Michael G Schwern <schwern@pobox.com> | ||||||||||||||||||||
| 169 | with apologies to Mark "I am not ominous" Dominus for further abuse | ||||||||||||||||||||
| 170 | of his code. | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | =head1 LICENSE and COPYRIGHT | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | Copyright 2001-2008 Michael G Schwern E<lt>schwern@pobox.comE<gt>. | ||||||||||||||||||||
| 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<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head1 SEE ALSO | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | y2k.pm, D'oh::Year, a good therapist | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 1 | "Yes, this code is a joke."; | |||||||||||||||||||