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
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 729
Download (untitled) / with headers
text/plain 729b
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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-10813-1329695909-670.73210-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 1041
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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.