my $cube = new Cubicle;
$cube->add(new Coder);
my $thing = $cube->query;
print "\L
$thing->{sound}
comes the sound from a @{[ref($cube)]}.
is it a guinea pig?
@{[ref($thing) eq 'Pig::guinea' ? 'yes' : 'no']}
is it a coder?
@{[ref($thing) eq 'Coder' ? 'yes' : 'no']}
is the coder a guinea pig?
@{[$thing->isa('Pig::guinea') ? 'yes' : 'no']}
";
package Pig::guinea;
sub new {bless{sound=>('ernk 'x3)},shift}
package Coder;
use base Pig::guinea;
sub new {bless{sound=>('tap 'x3)},shift}
package Cubicle;
sub new {bless{contents=>[]},shift}
sub add {push @{shift->{contents}},shift}
sub query {pop @{shift->{contents}}}
|