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;
16 use Mouse::Util::TypeConstraints;
20 => where { $_ =~ m{^[mf]$}s };
22 has 'gender' => ( is => 'ro', isa => 'Gender', required => 1 );
24 has 'mother' => ( is => 'ro', isa => 'Human' );
25 has 'father' => ( is => 'ro', isa => 'Human' );
27 use overload '+' => \&_overload_add, fallback => 1;
30 my ( $one, $two ) = @_;
32 die('Only male and female humans may create children')
33 if ( $one->gender() eq $two->gender() );
35 my ( $mother, $father )
36 = ( $one->gender eq 'f' ? ( $one, $two ) : ( $two, $one ) );
39 $gender = 'm' if ( rand() >= 0.5 );
43 eye_color => ( $one->eye_color() + $two->eye_color() ),
49 use List::MoreUtils qw( zip );
51 coerce 'Human::EyeColor'
53 => via { my @genes = qw( bey2_1 bey2_2 gey_1 gey_2 );
54 return Human::EyeColor->new( zip( @genes, @{$_} ) ); };
58 isa => 'Human::EyeColor',
66 package Human::Gene::bey2;
69 use Mouse::Util::TypeConstraints;
71 type 'bey2_color' => where { $_ =~ m{^(?:brown|blue)$} };
73 has 'color' => ( is => 'ro', isa => 'bey2_color' );
77 package Human::Gene::gey;
80 use Mouse::Util::TypeConstraints;
82 type 'gey_color' => where { $_ =~ m{^(?:green|blue)$} };
84 has 'color' => ( is => 'ro', isa => 'gey_color' );
88 package Human::EyeColor;
91 use Mouse::Util::TypeConstraints;
93 coerce 'Human::Gene::bey2'
95 => via { Human::Gene::bey2->new( color => $_ ) };
97 coerce 'Human::Gene::gey'
99 => via { Human::Gene::gey->new( color => $_ ) };
101 has [qw( bey2_1 bey2_2 )] =>
102 ( is => 'ro', isa => 'Human::Gene::bey2', coerce => 1 );
104 has [qw( gey_1 gey_2 )] =>
105 ( is => 'ro', isa => 'Human::Gene::gey', coerce => 1 );
111 if ( $self->bey2_1->color() eq 'brown'
112 or $self->bey2_2->color() eq 'brown' );
115 if ( $self->gey_1->color() eq 'green'
116 or $self->gey_2->color() eq 'green' );
121 use overload '""' => \&color, fallback => 1;
123 use overload '+' => \&_overload_add, fallback => 1;
126 my ( $one, $two ) = @_;
128 my $one_bey2 = 'bey2_' . _rand2();
129 my $two_bey2 = 'bey2_' . _rand2();
131 my $one_gey = 'gey_' . _rand2();
132 my $two_gey = 'gey_' . _rand2();
134 return Human::EyeColor->new(
135 bey2_1 => $one->$one_bey2->color(),
136 bey2_2 => $two->$two_bey2->color(),
137 gey_1 => $one->$one_gey->color(),
138 gey_2 => $two->$two_gey->color(),
143 return 1 + int( rand(2) );
147 my $gene_color_sets = [
148 [ qw( blue blue blue blue ) => 'blue' ],
149 [ qw( blue blue green blue ) => 'green' ],
150 [ qw( blue blue blue green ) => 'green' ],
151 [ qw( blue blue green green ) => 'green' ],
152 [ qw( brown blue blue blue ) => 'brown' ],
153 [ qw( brown brown green green ) => 'brown' ],
154 [ qw( blue brown green blue ) => 'brown' ],
157 foreach my $set (@$gene_color_sets) {
158 my $expected_color = pop(@$set);
160 my $person = Human->new(
166 $person->eye_color(),
178 [qw( blue blue blue blue )],
179 [qw( blue blue blue blue )] => 'blue'
182 [qw( blue blue blue blue )],
183 [qw( brown brown green blue )] => 'brown'
186 [qw( blue blue green green )],
187 [qw( blue blue green green )] => 'green'
191 foreach my $set (@$parent_sets) {
192 my $expected_color = pop(@$set);
194 my $mother = Human->new(
196 eye_color => shift(@$set),
199 my $father = Human->new(
201 eye_color => shift(@$set),
204 my $child = $mother + $father;
210 . $mother->eye_color()
212 . $father->eye_color()
218 # Hmm, not sure how to test for random selection of genes since
219 # I could theoretically run an infinite number of iterations and
220 # never find proof that a child has inherited a particular gene.
222 # AUTHOR: Aran Clary Deltac <bluefeet@cpan.org>