2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
15 use Mouse::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',
31 lives_ok { my $goat = Animal->new( leg_count => 4 ) }
32 '... no errors thrown, value is good';
33 lives_ok { my $spider = Animal->new( leg_count => 8 ) }
34 '... no errors thrown, value is good';
36 throws_ok { my $fern = Animal->new( leg_count => 0 ) }
37 qr/This number \(0\) is not less than ten!/,
38 'gave custom supertype error message on new';
40 throws_ok { my $centipede = Animal->new( leg_count => 30 ) }
41 qr/This number \(30\) is not less than ten!/,
42 'gave custom subtype error message on new';
45 lives_ok { $chimera = Animal->new( leg_count => 4 ) }
46 '... no errors thrown, value is good';
48 throws_ok { $chimera->leg_count(0) }
49 qr/This number \(0\) is not less than ten!/,
50 'gave custom supertype error message on set to 0';
52 throws_ok { $chimera->leg_count(16) }
53 qr/This number \(16\) is not less than ten!/,
54 'gave custom subtype error message on set to 16';
56 my $gimp = eval { Animal->new() };
57 is( $@, '', '... no errors thrown, value is good' );
59 throws_ok { $gimp->leg_count }
60 qr/This number \(0\) is not less than ten!/,
61 'gave custom supertype error message on lazy set to 0';