{ package Cow;
sub sound { "moooo" }
sub speak {
- my $class = shift;
- print "a $class goes ", $class->sound, "!\n";
+ my $class = shift;
+ print "a $class goes ", $class->sound, "!\n";
}
}
{ package Horse;
sub sound { "neigh" }
sub speak {
- my $class = shift;
- print "a $class goes ", $class->sound, "!\n";
+ my $class = shift;
+ print "a $class goes ", $class->sound, "!\n";
}
}
{ package Animal;
sub speak {
- my $class = shift;
- print "a $class goes ", $class->sound, "!\n";
+ my $class = shift;
+ print "a $class goes ", $class->sound, "!\n";
}
}
sub sound { "squeak" }
sub speak {
my $class = shift;
- print "a $class goes ", $class->sound, "!\n";
- print "[but you can barely hear it!]\n";
+ print "a $class goes ", $class->sound, "!\n";
+ print "[but you can barely hear it!]\n";
}
}
sub speak {
my $class = shift;
Animal::speak($class);
- print "[but you can barely hear it!]\n";
+ print "[but you can barely hear it!]\n";
}
}
sub name {
my $either = shift;
ref $either
- ? $$either # it's an instance, return name
- : "an unnamed $either"; # it's a class, return generic
+ ? $$either # it's an instance, return name
+ : "an unnamed $either"; # it's a class, return generic
}
sub speak {
my $either = shift;