sub gmtime {
my $time = shift;
$time = time if (!defined $time);
_mktime($time, 0);
}
sub _mktime {
my ($time, $islocal) = @_;
if (ref($time)) {
$time->[c_epoch] = undef;
return wantarray ? @$time : bless [@$time, $islocal],
'Time::Piece';
}
my @time = $islocal ?
CORE::localtime($time)
:
CORE::gmtime($time);
wantarray ? @time : bless [@time, $time, $islocal], 'Time::Piece';
}
####
package Time::MyPiece;
use base 'Time::Piece';
my $SUPER;
foreach (@ISA) {
$SUPER = $_ and last if $_->can('_mktime');
}
...
sub _mktime {
my $t;
eval "$t = $SUPER::_mktime(@_)";
}
####
sub _mktime {
my ($time, $islocal) = @_;
my $class;
if (ref $time) {
$class = ref $time;
}
elsif ($time =~ /^\D+$/) {
$class = $time;
$time = $class->new(@_);
}
if (ref($time)) {
$time->[c_epoch] = undef;
return wantarray ? @$time : bless [@$time, $islocal], $class;
}
my @time = $islocal ?
CORE::localtime($time)
:
CORE::gmtime($time);
wantarray ? @time : bless [@time, $time, $islocal], $class;
}