1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
use strict;
use warnings;
use Test::More tests => 16;
use MouseX::Types::Mouse qw(ArrayRef HashRef Maybe Str);
my $t = ArrayRef[Str];
ok ref $t, "ArrayRef[Str]";
ok $t->is_a_type_of(ArrayRef);
ok $t->check([qw(Foo)]);
ok!$t->check([ [] ]);
$t = HashRef[Str];
ok ref $t, "HashRef[Str]";
ok $t->is_a_type_of(HashRef);
ok $t->check({foo => "bar"});
ok!$t->check({foo => {} });
$t = Maybe[Str];
ok ref $t, "Maybe[Str]";
ok $t->is_a_type_of(Maybe);
ok $t->check("foo");
ok $t->check(undef);
ok!$t->check({});
eval {
$t = Str[Str];
};
ok $@;
eval {
$t = ArrayRef([Str, Str]);
};
ok $@;
eval q{
package Class;
use Mouse;
use MouseX::Types::Mouse qw(ArrayRef Str);
has foo => (
is => 'rw',
isa => ArrayRef[Str],
required => 1,
);
};
is $@, '';
|