Subject: | report "garbage at end of string in strptime" from caller's perspective |
$ perl -MTime::Piece -le 'print $Time::Piece::VERSION;$a = Time::Piece->strptime("2013 garbage", "%Y");'
1.23
garbage at end of string in strptime: garbage at /home/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/i686-linux/Time/Piece.pm line 469.
It would be much nicer if Time::Piece reported this error from the perspective of the caller instead of in Time::Piece itself. It is of no real use to know it fell over in Time::Piece.
This changed strptime does it for me:
sub strptime {
my $time = shift;
my $string = shift;
my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S %Z";
my (@vals, $warning);
{
local $SIG{__WARN__} = sub {$warning = shift};
@vals = _strptime($string, $format);
}
carp($warning) if $warning;
# warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals)));
return scalar $time->_mktime(\@vals, (ref($time) ? $time->[c_islocal] : 0));
}
Martin
--
Martin J. Evans
Wetherby, UK