package Animal; use strict; sub new { my $class = shift; my $name = shift || "Rose"; my $color = shift || $class->default_color(); my $objref = { name => $name, color => $color }; bless $objref, $class; } sub default_color { "brown"; } sub speak { my $either = shift; print $either->get_name() . " says " . $either->sound() . "\n"; } sub get_name { my $either = shift; ref $either ? $either->{name} : "A generic $either"; } sub set_name { my $self = shift; my $name = shift; $self->{name} = $name; } sub get_color { my $either = shift; ref $either ? $either->{color} : $either->default_color(); } sub set_color { my $self = shift; my $color = shift; $self->{color} = $color; } 1;