Created
June 30, 2009 09:34
-
-
Save draegtun/138092 to your computer and use it in GitHub Desktop.
Simple Moose class inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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