sub color {
my $shift;
if (@_) { # are there any more parameters?
# yes, it's a setter:
$self->{Color} = shift;
} else {
# no, it's a getter:
$self->{Color};
}
}
Now you can say:
my $tv_horse = Horse->named("Mr. Ed");
$tv_horse->color("black-and-white");
print $tv_horse->name, " is colored ", $tv_horse->color, "\n";
The presence of the parameter in the second line denotes that you are
setting the color, while its absence in the third line indicates a
getter.