Skip to content

Instantly share code, notes, and snippets.

@draegtun
Created June 30, 2009 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draegtun/138092 to your computer and use it in GitHub Desktop.
Save draegtun/138092 to your computer and use it in GitHub Desktop.
Simple Moose class inheritance
#!/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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment