use warnings;
use strict;
-use Test::More tests => 26;
+use Test::More tests => 29;
use Test::Exception;
use FindBin;
use lib "$FindBin::Bin/lib";
Int
);
use DecoratorLibrary qw(
- MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02
+ MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02 StrOrArrayRef
);
has 'arrayrefbase' => (is=>'rw', isa=>MyArrayRefBase, coerce=>1);
has 'arrayrefint01' => (is=>'rw', isa=>MyArrayRefInt01, coerce=>1);
has 'arrayrefint02' => (is=>'rw', isa=>MyArrayRefInt02, coerce=>1);
has 'arrayrefint03' => (is=>'rw', isa=>MyArrayRefBase[Int]);
+ has 'StrOrArrayRef' => (is=>'rw', isa=>StrOrArrayRef);
}
## Make sure we have a 'create object sanity check'
throws_ok sub {
$type->arrayrefint03([qw(a b c)])
-}, qr/Attribute \(arrayrefint03\) does not pass the type constraint/ => 'Dies when values are strings';
\ No newline at end of file
+}, qr/Attribute \(arrayrefint03\) does not pass the type constraint/ => 'Dies when values are strings';
+
+# TEST StrOrArrayRef
+
+ok $type->StrOrArrayRef('string')
+ => 'String part of union is good';
+
+ok $type->StrOrArrayRef([1,2,3])
+ => 'arrayref part of union is good';
+
+throws_ok sub {
+ $type->StrOrArrayRef({a=>111});
+}, qr/Attribute \(StrOrArrayRef\) does not pass the type constraint/ => 'Correctly failed to use a hashref';
\ No newline at end of file