use warnings;
use strict;
-use Test::More tests => 49;
+use Test::More tests => 52;
use Test::Exception;
use FindBin;
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);
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'
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
StrOrArrayRef
AtLeastOneInt
Jobs
+ SubOfMyArrayRefInt01
+ BiggerInt
)];
subtype 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('\.',$_)]},