Subject: | problem caused by the call to Moose::Util::TypeConstraint ::find_or_parse_type_constraints($_{isa}) |
Date: | Wed, 29 Jan 2014 12:26:09 +0000 |
To: | bug-MooseX-MungeHas [...] rt.cpan.org |
From: | mascip <mascip [...] gmail.com> |
Hi Toby,
line number 67, in compile_munger_code(), causes me a problem (bug?). It's
this line:
push @code, ' $_{isa} =
'._detect_oo($caller).'::Util::TypeConstraints::find_or_parse_type_constraint($_{isa});';
Here is enough code to provoke the bug:
package Bfp::API;
use OX; # use Moose; here leads to the exact same bug
use MooseX::MungeHas 'is_ro';
has view => ( isa => 'OX::View::TT' );
I've added some print statements in MooseX::MungeHas, and found that before
line 67,
$_{isa} is equal to 'OX::View::TT'
but after that line it is undef, because
Moose::Util::TypeConstraints::find_or_parse_type_constraint($_{isa})
doesn't "find" nor "detects" the 'OX::View::TT' type.
I'm not sure whether it's a bug in Moose::Util::TypeConstraints (I'm not
sure how its $REGISTER and find_or_parse_type_constraint() are supposed to
behave exactly), or whether MooseX::MungeHas should not be using this
function - or use something else instead.
But I have tried to simply comment line 67 in MooseX::MungeHas, and there
is no more bug: everything seems to work seamlessly. What is the purpose
for calling this function here? Do we really need it sometimes?
I have made one additional experiment which might give some insight. By
adding one line in the code:
use OX::View::TT;
the type is found and everything works well.
But that's annoying: without MooseX::MungeHas I didn't need to add this
line. Why would I now have to? That's especially annoying if I've got a few
classes with a few attributes each: for each attribute, I'm going to have
to add the right "use" line if I want to use MooseX::MungeHas.
There's no rush in fixing this problem for me: right now I'm using your
code with line 67 commented and it works. But that feels potentially
dangerous.
PS:
Ah! I forgot to write the minimal extra amount of code that i use to run
this code:
package Bfp;
use OX;
use Bfp::API;
router as {
mount '/api' => 'Bfp::API', (
view_index => 'view',
);
};
which I run with
plackup -Ilib bin/app.psgi