public
Last active

Simple Moose class inheritance

  • Download Gist
Animal.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/local/bin/perl
 
{
package Animal;
use Moose;
 
has extinct => ( isa => 'Bool', is => 'rw' );
 
no Moose;
}
 
{
package Cat;
use Moose;
extends 'Animal';
has breed => ( isa => 'Str', is => 'rw' );
 
sub legs { 4 }
sub says { "miaow!" }
 
no Moose;
}
 
{
package Dog;
use Moose;
extends 'Animal';
has breed => ( isa => 'Str', is => 'rw' );
 
sub legs { 4 }
sub says { "woof!" }
 
no Moose;
}
 
{
package Fish;
use Moose;
extends 'Animal';
has breed => ( isa => 'Str', is => 'rw' );
 
sub says { "gurgles!" }
 
no Moose;
}
 
{
package PetDog;
use Moose;
extends 'Dog';
has "name" => ( isa => 'Str', is => 'rw' );
no Moose;
}
 
 
my $dog = PetDog->new( breed => 'Dalmation', name => 'Spot' );
print $dog->breed, "\n";

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.