Skip Menu |

This queue is for tickets about the MooseX-Types CPAN distribution.

Report information
The Basics
Id: 77303
Status: stalled
Priority: 0/
Queue: MooseX-Types

People
Owner: Nobody in particular
Requestors: cjm [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 0.32
  • 0.35
Fixed in: (no value)



Subject: Union of class type & role type is broken in 0.32-0.35
I'm getting reports that recent versions of MooseX::Types break my PostScript::Report module. See https://rt.cpan.org/Ticket/Display.html?id=77299 and http://www.cpantesters.org/cpan/report/6db9cd6c-a13d-11e1-b2dc-032bf4b14d39 From my testing, it started with MooseX::Types 0.32, and includes all versions up to and including 0.35. I've narrowed it down to a union between a role_type and a class_type. From https://github.com/madsen/postscript-report/blob/master/lib/PostScript/Report/Types.pm#L55 subtype Container, as role_type('PostScript::Report::Role::Container'); ... subtype Report, as class_type('PostScript::Report'); ... subtype Parent, as Container|Report; When I try to load PostScript::Report::Types with the current MooseX::Types, I get: Can't call method "does_role" on an undefined value at /usr/lib/perl5/vendor_perl/5.14.2/i686-linux/Moose/Meta/TypeConstraint/Role.pm line 101. That's with Moose 2.0602. Interestingly, changing the last line to repeat the definitions allows the type library to load: as role_type('PostScript::Report::Role::Container')|class_type('PostScript::Report'); But that doesn't completely solve the problem, because I still get the same error when loading PostScript::Report.
Here's a minimal test case: #! /usr/bin/perl use strict; use warnings; use MooseX::Types -declare => [qw( RoleFoo ClassFoo UnionFoo )]; subtype RoleFoo, as role_type( 'Foo::Role'); subtype ClassFoo, as class_type('Foo::Class'); subtype UnionFoo, as RoleFoo|ClassFoo; This script works fine with MooseX::Types 0.31. With 0.32 or later, it fails with Can't call method "does_role" on an undefined value at .../Moose/Meta/TypeConstraint/Role.pm line 101.
On further research, this appears to happen because the role hasn't been defined yet. If I add the line { package Foo::Role; use Moose::Role; } then the script completes without error. But this isn't a solution for PostScript::Report, because the roles define attributes using the types defined by PostScript::Report::Types. Therefore, I can't define the roles before defining the types mentioning them.
On Mon May 21 03:17:49 2012, CJM wrote: Show quoted text
> On further research, this appears to happen because the role hasn't been > defined yet. If I add the line > > { package Foo::Role; use Moose::Role; } > > then the script completes without error. But this isn't a solution for > PostScript::Report, because the roles define attributes using the types > defined by PostScript::Report::Types. Therefore, I can't define the > roles before defining the types mentioning them.
I think what you should actually be writing is: role_type Container, { role => 'PostScript::Report::Role::Container') }; class_type Report, { class => 'PostScript::Report' }; but that doesn't mean what you were writing before should've broken; I'll have a squizz.
I made the changes you suggested (see the new https://github.com/madsen/postscript-report/tree/moosex-types branch), and that does allow the type library to load, but I'm still getting the same error; just somewhere else: Unable to load PostScript::Report::Field: Could not create the 'reader' method for value because : Could not generate inline reader because : Could not create writer for 'value' because Can't call method "does_role" on an undefined value at .../Moose/Meta/TypeConstraint/Role.pm line 101, <DATA> line 133. RptValue (the type involved) is a union of Str and a role, so maybe it's unions of role_type and anything that are broken.
I was able to find a nasty hack to get PostScript::Report working with MooseX::Types 0.35 (see the moosex-types branch I mentioned on GitHub). (It still doesn't work with 0.32-0.34.) At the beginning of my type library, I create empty roles: { package PostScript::Report::Role::Component; use Moose::Role; } { package PostScript::Report::Role::Container; use Moose::Role; } { package PostScript::Report::Role::Value; use Moose::Role; } Then I can define types using those roles, and they work. But at the end of the type library, I have to load the roles manually: require PostScript::Report::Role::Value; require PostScript::Report::Role::Component; require PostScript::Report::Role::Container; Otherwise, "with" won't load them (presumably because it thinks they're already defined) and classes that use them won't work. This is not a very good solution. You really need to fix this in MooseX::Types.
On 2012-07-05 09:33:23, CJM wrote: Show quoted text
Did that get released? can this ticket be closed?