Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active August 29, 2015 13:56
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 tobyink/8931339 to your computer and use it in GitHub Desktop.
Save tobyink/8931339 to your computer and use it in GitHub Desktop.
package main;
use Moops;
class Character {
has name => (is => 'ro', isa => Str);
method BUILD ($p) {
my $race = $p->{race} // 'Human';
Moo::Role->apply_roles_to_object($self, "Race::$race");
}
}
namespace Race {
role HalfElf;
role Elf with HalfElf; # all elves are half-elves
role Dwarf;
role Gnome;
role Halfling;
role Human;
role Wizard {
method cast_spell () {
say "Abracadabra!";
}
}
}
my $james = Character->new(
name => 'Gandalfini',
race => 'Wizard',
);
$james->cast_spell
if $james->DOES('Race::Wizard');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment