6 use Test::More tests => 9;
12 use Mouse::Util::TypeConstraints;
14 subtype 'Natural' => as 'Int' => where { $_ > 0 } =>
15 message {"This number ($_) is not a positive integer!"};
17 subtype 'NaturalLessThanTen' => as 'Natural' => where { $_ < 10 } =>
18 message {"This number ($_) is not less than ten!"};
22 isa => 'NaturalLessThanTen',
28 lives_ok { my $goat = Animal->new( leg_count => 4 ) }
29 '... no errors thrown, value is good';
30 lives_ok { my $spider = Animal->new( leg_count => 8 ) }
31 '... no errors thrown, value is good';
33 throws_ok { my $fern = Animal->new( leg_count => 0 ) }
34 qr/This number \(0\) is not less than ten!/,
35 'gave custom supertype error message on new';
37 throws_ok { my $centipede = Animal->new( leg_count => 30 ) }
38 qr/This number \(30\) is not less than ten!/,
39 'gave custom subtype error message on new';
42 lives_ok { $chimera = Animal->new( leg_count => 4 ) }
43 '... no errors thrown, value is good';
45 throws_ok { $chimera->leg_count(0) }
46 qr/This number \(0\) is not less than ten!/,
47 'gave custom supertype error message on set to 0';
49 throws_ok { $chimera->leg_count(16) }
50 qr/This number \(16\) is not less than ten!/,
51 'gave custom subtype error message on set to 16';
53 my $gimp = eval { Animal->new() };
54 is( $@, '', '... no errors thrown, value is good' );
56 throws_ok { $gimp->leg_count }
57 qr/This number \(0\) is not less than ten!/,
58 'gave custom supertype error message on lazy set to 0';