Skip Menu |

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

Report information
The Basics
Id: 50057
Status: resolved
Priority: 0/
Queue: MooseX-Types

People
Owner: Nobody in particular
Requestors: dave [...] jetcafe.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.19
Fixed in: (no value)



Subject: MooseX::Types does not play nice with MooseX::AttributeHelpers
Given the two following library: __MyLib.pm__ package MyLib; use MooseX::Types -declare => [ qw(PositiveInt) ]; use MooseX::Types::Moose qw( Int ); subtype PositiveInt, as Int, where { $_ >= 0 }, message { "Value $_ must be a positive integer or zero"; }; 1; __End of MyLib.pm__ and this main: package Foo; use lib '.'; use Moose; use MooseX::AttributeHelpers; use MyLib qw(:all); has 'bar' => ( isa => PositiveInt, is => 'ro', writer => 'set_bar', default => 'default' ); has foo => ( metaclass => 'Collection::Array', is => 'ro', isa => 'ArrayRef[PositiveInt]', init_arg => undef, default => sub { []; }, lazy => 1, provides => { 'set' => 'set_foo', 'get' => 'get_foo', }, ); no Moose; __PACKAGE__->meta->make_immutable; package main; my $x = Foo->new( bar => 1 ); print "Foo->bar is ".$x->bar()."\n"; $x->set_foo(1,1); the method "set_foo" will fail this way: Value 1 did not pass container type constraint 'PositiveInt' at /usr/local/lib/perl5/site_perl/5.8.9/MooseX/AttributeHelpers/MethodProvider/Array.pm line 77 Foo::set_foo('Foo=HASH(0x28c3db28)', 1, 1) called at ./mt4 line 33 Here is other pertinent information: Show quoted text
> uname -rs
FreeBSD 7.2-RELEASE-p1 Show quoted text
> perl -v
This is perl, v5.8.9 built for i386-freebsd-thread-multi-64int (with 1 registered patch, see perl -V for more detail)
On Sun Sep 27 22:07:21 2009, dave@jetcafe.org wrote: Show quoted text
> has foo => ( > metaclass => 'Collection::Array', > is => 'ro', isa => 'ArrayRef[PositiveInt]', > init_arg => undef, default => sub { []; }, lazy => 1, > provides => { > 'set' => 'set_foo', > 'get' => 'get_foo', > }, > );
You meant to say isa => ArrayRef[PositiveInt], instead of isa => 'ArrayRef[PositiveInt]', With that, it all works just fine, assuming you're also importing the ArrayRef type from MooseX::Types::Moose.
Ah I see. Thanks for this information. Is it possible to add this necessary clarification to the documentation? One gets used to stringified isa values from doing basic Moose, and this might save another confused ticket. Thanks again.