Dave Rolsky schreef:
> On Thu, 29 May 2003, Rick Measham wrote:
>
> > The behaviour now remains the same, however if you set
> > $DateTime::Format::StrpTime::CROAK to false, methods will
> > return undef rather than croaking.
> > $DateTime::Format::StrpTime::errmsg will tell you what went
> > wrong.
>
> Globals for behavior like this are a big PITA. This is not the right
> solution to the problem.
The right solution would be (IMHO, of course) to store the selected
behaviour in the formatter/parser object:
my $Strp = DateTime::Format::Strptime(
pattern => '%T',
language => 'English',
time_zone=> 'Melbourne/Australia',
on_error => 'croak',
# or: on_error => 'undef',
# or: on_error => sub{ return DateTime->now },
);
If you implement the last option, arbritrary on_error functions, this
becomes possible:
my $Strp_min = DateTime::Format::Strptime(
pattern => '%H:%M',
on_error => 'croak',
)
my $Strp = DateTime::Format::Strptime(
pattern => '%H:%M:%S',
on_error => sub { return $Strp_min->parse_datetime($_[2])
if $_[0] eq 'parse_datetime' }
)
The following arguments could be passed to the sub:
$_[0]: method in which the error occurs
$_[1]: description of the error (the text normally passed to croak)
@_[2...$#_]: arguments of the method in which the error occurs
Eugene