use 5.10.0;
package Animal;
sub speak {
my $self = shift;
ref $self and $self = ref $self;
say "$self says: ", $self->word;
}
package Cow;
@Cow::ISA = qw(Animal);
sub word { "moo" }
package Dog;
@Cow::ISA = qw(Animal);
sub word { "wuff" }
package main;
Cow->speak;
Dog->speak;
__END__
Cow says: moo
Dog says: wuff
####
shift if $_[0] eq __PACKAGE__ || ref $_[0] eq __PACKAGE__;
####
use Animal; # contains Cow and Dog as above
Cow->speak;
speak Cow;
my $animal = 'Cow';
$animal->speak;
speak $animal;
Animal::speak('Cow');
$animal = bless do{\my $x}, 'Cow';
Animal::speak($animal);
$animal->speak;