Subject: | Params::Validate fails in __DIE__ handler with "Modification of a read-only value attempted" |
I'm getting this error message:
Show quoted text
> Modification of a read-only value attempted at script.pl line 8.
From the following script.pl . Why is that?
#!/usr/bin/perl -w
use strict;
use Params::Validate;
BEGIN {
$SIG{__DIE__} = sub {
my %args = Params::Validate::validate( @_, {});
};
}
my $foo = $nonExistingVar;
The error is misleading, as it is clear that the caller of validate(),
script.pl, is not modifying any read-only value.
This does what I expect:
#!/usr/bin/perl -w
use strict;
BEGIN {
$SIG{__DIE__} = sub {
print "Normal __DIE__ handler: ", join("", @_);
exit 1;
};
}
my $foo = $nonExistingVar;
and outputs:
Show quoted text> Normal __DIE__ handler: Global symbol "$nonExistingVar"
> requires explicit package name at normalDie.pl line 11.
> Execution of normalDie.pl aborted due to compilation errors.
The reason I'm doing this is that I want to use Log::Log4Perl in my
__DIE__ handler. It ends up calling Log::Dispatch's
Log::Dispatch::Output::log method, and it in turn uses validate()
which fails (it also has some more params to validate() etc.). But
this is the minimal example I could come up with.
I've tried various arrays instead of @_ and I've tried with the default
debian libparams-validate-perl 0.91-2, the 0.95 from CPAN and the hg
tip, all with the same result.
Peter