Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Perl Monks,
I am trying to use the new MooseX::Declare syntax, in conjunction with Moose subtypes. Here is my code:This code gives the following error when executed:use strict; use v5.10; use MooseX::Declare; use Moose::Util::TypeConstraints; subtype 'PositiveInt' => as 'Int' => where { $_ > 0 } => message { "Number '$_' is not positive" }; class BankAccount { use MooseX::StrictConstructor; has balance => ( isa => 'Int', is => 'rw', default => 0 ); method deposit ( PositiveInt :$amount ) { $self->balance( $self->balance + $amount ); } } my $a = BankAccount->new( balance => 100 ); $a->deposit( amount => 50 ); say $a->balance;
I haven't been able to find a class_type() method in the MooseX::Declare documentation. Could someone enlighten me about what should be done ?'PositiveInt' could not be parsed to a type constraint - maybe you nee +d to pre-declare the type with class_type at /home/moose/perl5/lib/pe +rl5/MooseX/Declare/Syntax/MethodDeclaration.pm line 40
Thank you in advance
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: MooseX::Declare and Moose subtypes
by merlyn (Sage) on Feb 23, 2010 at 02:05 UTC | |
by Anonymous Monk on Feb 23, 2010 at 21:38 UTC |
Back to
Seekers of Perl Wisdom