From: John Napiorkowski Date: Fri, 24 Oct 2008 20:16:55 +0000 (+0000) Subject: added a tags directory for releases X-Git-Tag: 0.07~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types.git;a=commitdiff_plain;h=48a2379be806b65d1a0e348e7ba7ca6a9aa00dea added a tags directory for releases --- diff --git a/t/13_typedecorator.t b/t/13_typedecorator.t index 3f250e6..e22aca5 100644 --- a/t/13_typedecorator.t +++ b/t/13_typedecorator.t @@ -2,7 +2,7 @@ use warnings; use strict; -use Test::More tests => 49; +use Test::More tests => 52; use Test::Exception; use FindBin; use lib "$FindBin::Bin/lib"; @@ -16,7 +16,7 @@ use lib "$FindBin::Bin/lib"; ); use DecoratorLibrary qw( MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02 StrOrArrayRef - AtLeastOneInt Jobs + AtLeastOneInt Jobs SubOfMyArrayRefInt01 ); has 'arrayrefbase' => (is=>'rw', isa=>MyArrayRefBase, coerce=>1); @@ -29,6 +29,7 @@ use lib "$FindBin::Bin/lib"; has 'deep' => (is=>'rw', isa=>ArrayRef[ArrayRef[HashRef[Int]]] ); has 'deep2' => (is=>'rw', isa=>ArrayRef[Int|ArrayRef[HashRef[Int|Object]]] ); has 'enum' => (is=>'rw', isa=>Jobs); + has 'SubOfMyArrayRefInt01_attr' => (is=>'rw', isa=>SubOfMyArrayRefInt01); } ## Make sure we have a 'create object sanity check' @@ -213,3 +214,15 @@ ok $type->enum('Programming') throws_ok sub { $type->enum('ddddd'); }, qr/Attribute \(enum\) does not pass the type constraint/ => 'Enum properly fails'; + +## Test SubOfMyArrayRefInt01_attr + +ok $type->SubOfMyArrayRefInt01_attr([15,20,25]) + => 'Assigned SubOfMyArrayRefInt01_attr to [15,20,25]'; + +is_deeply $type->SubOfMyArrayRefInt01_attr, [15,20,25], + => 'Assignment is correct'; + +throws_ok sub { + $type->SubOfMyArrayRefInt01_attr([15,5,20]); +}, qr/Attribute \(SubOfMyArrayRefInt01_attr\) does not pass the type constraint/ => 'SubOfMyArrayRefInt01 Constraints properly fail'; \ No newline at end of file diff --git a/t/lib/DecoratorLibrary.pm b/t/lib/DecoratorLibrary.pm index 0aef0cd..8361866 100644 --- a/t/lib/DecoratorLibrary.pm +++ b/t/lib/DecoratorLibrary.pm @@ -11,6 +11,8 @@ use MooseX::Types StrOrArrayRef AtLeastOneInt Jobs + SubOfMyArrayRefInt01 + BiggerInt )]; subtype MyArrayRefBase, @@ -23,6 +25,27 @@ coerce MyArrayRefBase, subtype MyArrayRefInt01, as ArrayRef[Int]; +subtype BiggerInt, + as Int, + where {$_>10}; + +## We can change this when the .61 Moose comes out. When that happens we will +## have the correct patch to Moose::Meta::TypeConstraint::Parameterized to let +## us support parameterizing parameterized subtypes. When we get this we can +## then replace the where clause with: + + ##as MyArrayRefInt01[BiggerInt]; + +subtype SubOfMyArrayRefInt01, + as MyArrayRefInt01, + where { + my $ok_or_not = 1; + foreach my $int (@$_) { + $ok_or_not = $int>10 ? 1:0 + if $ok_or_not; + } $ok_or_not; + }; + coerce MyArrayRefInt01, from Str, via {[split('\.',$_)]},