=head1 DESCRIPTION
This Moose cookbook recipe shows how operator overloading, coercion,
-and sub types can be used to mimic the human reproductive system
+and subtypes can be used to mimic the human reproductive system
(well, the selection of genes at least).
=head1 INTRODUCTION
has 'color' => ( is => 'ro', isa => 'bey2_color' );
-This class is trivial, We have a type constraint for the allowed
+This class is trivial. We have a type constraint for the allowed
colors, and a C<color> attribute.
=head2 Human::Gene::gey
=head1 EYE COLOR
-We could just give add four attributes (two of each gene) to the
+We could just give four attributes (two of each gene) to the
C<Human> class, but this is a bit messy. Instead, we'll abstract the
genes into a container class, C<Human::EyeColor>. Then a C<Human> can
have a single C<eye_color> attribute.
"indigo", because that is not a valid color for either type of gene.
As an aside, you can see that we can define several identical
-attributes at once by supply an array reference of names as the first
+attributes at once by supplying an array reference of names as the first
argument to C<has>.
We also need a method to calculate the actual eye color that results
from a set of genes. The I<bey2> brown gene is dominant over both blue
-and green. The I<gey> green gene dominant over blue.
+and green. The I<gey> green gene is dominant over blue.
sub color {
my ($self) = @_;
use overload '""' => \&color, fallback => 1;
Finally, we need to define overloading for addition. That way we can
-add together to C<Human::EyeColor> objects and get a new one with a
+add together two C<Human::EyeColor> objects and get a new one with a
new (genetically correct) eye color.
use overload '+' => \&_overload_add, fallback => 1;
return 1 + int( rand(2) );
}
-When two eye color objects are added together the C<_overload_add()>
+When two eye color objects are added together, the C<_overload_add()>
method will be passed two C<Human::EyeColor> objects. These are the
left and right side operands for the C<+> operator. This method
returns a new C<Human::EyeColor> object.