Subject: | type checking for CPANPLUS::Backend::RV::new is incorrect |
Date: | Tue, 12 Jul 2011 01:12:05 -0700 |
To: | bug-cpanplus [...] rt.cpan.org |
From: | Carl <k0802647 [...] telus.net> |
I believe CPANPLUS::Backend::RV::new is type checking its 'ok' argument
incorrectly and thereby causing an error report which should not occur.
Explanation follows...
Lines 398-403 of CPANPLUS/Backend.pm are as follows:
return CPANPLUS::Backend::RV->new(
function => $func,
ok => !$flag,
rv => $href,
args => \%hash,
);
The value for key 'ok' is the logical negation of a non-negative
integer. If the integer is greater than zero, the logical negation is a
value of "", according to the Perl specification for the unary negation
operator. The CPANPLUS developers may have erroneously believed that
such a logical negation yields 0 rather than "".
Lines 92-97 of CPANPLUS/Backend/RV.pm are as follows:
my $tmpl = {
ok => { required => 1, allow => BOOLEANS },
args => { required => 1 },
rv => { required => 1 },
function => { default => CALLING_FUNCTION->() },
};
That is a template used by Params::Check to validate arguments to
CPANPLUS::Backend::RV->new() and shows that the 'ok' value must be of
type BOOLEANS.
Line 329 of CPANPLUS/Internals/Constants.pm is as follows:
use constant BOOLEANS => [0,1];
That constant declaration shows that a value of "" would be deemed
invalid because it is neither 0 nor 1. That is precisely what happens,
yielding this error message:
Key 'ok' () is of invalid type for 'CPANPLUS::Backend::RV::new'
provided by CPANPLUS::Backend::__ANON__ at
/usr/local/lib/perl5/5.12.3/CPANPLUS/Backend.pm line 398
There is evidence of this error happening for other folks too:
http://www.google.com/search?q="Key+'ok'+()+is+of+invalid+type+for+'CPANPLUS%3A%3ABackend%3A%3ARV%3A%3Anew'+provided+by+CPANPLUS%3A%3ABackend%3A%3A__ANON__"+"CPANPLUS%2FBackend.pm+line+398"
(http://tinyurl.com/6ha6vgj)
The fix either requires a change in declaration of BOOLEANS to allow for
the "" case or the CPANPLUS developers need to change line 400 in
CPANPLUS/Backend.pm to produce a value of only 0 or 1. It makes sense
that all CPANPLUS code should be audited for additional instances of
this kind of bug.
Carl