6 use Test::More tests => 10;
14 ::use_ok("Moose::Util::TypeConstraints");
17 subtype 'Natural' => as 'Int' => where { $_ > 0 } =>
18 message {"This number ($_) is not a positive integer!"};
20 subtype 'NaturalLessThanTen' => as 'Natural' => where { $_ < 10 } =>
21 message {"This number ($_) is not less than ten!"};
25 isa => 'NaturalLessThanTen',
33 lives_ok { my $goat = Animal->new( leg_count => 4 ) }
34 '... no errors thrown, value is good';
35 lives_ok { my $spider = Animal->new( leg_count => 8 ) }
36 '... no errors thrown, value is good';
38 throws_ok { my $fern = Animal->new( leg_count => 0 ) }
39 qr/This number \(0\) is not less than ten!/,
40 "gave custom supertype error message on new";
42 throws_ok { my $centipede = Animal->new( leg_count => 30 ) }
43 qr/This number \(30\) is not less than ten!/,
44 "gave custom subtype error message on new";
47 lives_ok { $chimera = Animal->new( leg_count => 4 ) }
48 '... no errors thrown, value is good';
50 # first we remove the lion's legs..
51 throws_ok { $chimera->leg_count(0) }
52 qr/This number \(0\) is not less than ten!/,
53 "gave custom supertype error message on set_value";
55 # mix in a few octopodes
56 throws_ok { $chimera->leg_count(16) }
57 qr/This number \(16\) is not less than ten!/,
58 "gave custom subtype error message on set_value";
62 lives_ok { my $gimp = Animal->new() } '... no errors thrown, value is good';
63 throws_ok { $gimp->leg_count }
64 qr/This number \(0\) is not less than ten!/,
65 "gave custom supertype error message on set_value";