Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 73210
Status: rejected
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: perl [...] evancarroll.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.0000
Fixed in: (no value)



Subject: Problem with type-unions and attribute traits in v2
It appears as if traits that are attached to type-unions now throw an error in Moose v2. Perhaps the mechanism that determines if the native trait is applicable should do more with the meta than look at the stringification of the type? Or, perhaps it should split on a /,|/ and see if any component part matches? By any means, this use to work with 1.x package Class; use Test::More tests => 1; use Moose; use MooseX::Types::Moose qw/Undef Str/; eval { has 'trait_boom' => ( is => 'rw' , isa => Str | Undef , default => '' , traits => ['String'] ); }; ok ( !$@, "Created attr trait_boom, a type union of Str and Undef\n$@" ); -- Evan Carroll System Lord of the Internets http://www.evancarroll.com
On Mon Dec 12 17:17:53 2011, ECARROLL wrote: Show quoted text
> It appears as if traits that are attached to type-unions now throw an > error in Moose v2. Perhaps the mechanism that determines if the native > trait is applicable should do more with the meta than look at the > stringification of the type? Or, perhaps it should split on a /,|/ and > see if any component part matches? > > By any means, this use to work with 1.x > > package Class; > use Test::More tests => 1; > use Moose; > > use MooseX::Types::Moose qw/Undef Str/; > > eval { > has 'trait_boom' => ( > is => 'rw' > , isa => Str | Undef > , default => '' > , traits => ['String'] > ); > }; > > ok ( !$@, "Created attr trait_boom, a type union of Str and Undef\n$@" > );
I'm not sure if the fact that this used to "work" was really intentional. If the value is actually undef, then the native trait methods for String make no sense. This would be even more nonsensical if we tried to apply the Array trait to a union of "ArrayRef[Int] | Int", for example.