--- author: email: rafl@fsfe.org keyid: 742f2a428e635a5e name: Florian Ragwitz categories: - Perl date: 2009-08-19T08:27:25Z guid: a9b71ca9-4050-4322-9afe-2f5e2ee9a776 modified: 2009-08-19T08:27:25Z raw: "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n=pod\n\nYou've probably already heard of Sartak's awesome\nL.\n\nAs of version 0.25, MooseX::Declare provides some nice sugar for\nthat. This is what it looks like:\n\n lang:Perl\n use MooseX::Declare;\n\n role Counter (Str :$name) {\n has $name => (is => 'rw', isa => 'Int', default => 0);\n\n method \"increment_${name}\" {\n $self->$name( $self->$name + 1 );\n }\n\n method \"reset_${name}\" {\n $self->$name(0);\n }\n }\n\n class MyGame::Weapon {\n with Counter => { name => 'enchantment' };\n }\n\n class MyGame::Wand {\n with Counter => { name => 'zapped' };\n }\n\nJust thought I'd let you know, since i haven't gotten around to\nactually document this. In case you like it, have some spare\ntuits, and want to help out, the repository is\nL :-)\n\n=cut\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n\niD8DBQFKi7dGdC8qQo5jWl4RAkm2AJ9m1S3kzkHl1zgMQfh2bU9pqFLnVwCcCNpN\nEMIF5I5VMLWrpy/ESf3Bs14=\n=9SN1\n-----END PGP SIGNATURE-----\n" signed: 1 summary: " You've probably already heard of Sartak's awesome MooseX::Role::Pa- rameterized. …" tags: - perl: 0 - moose: 0 - syntax: 0 text: " You've probably already heard of Sartak's awesome MooseX::Role::Pa-\n rameterized.\n\n As of version 0.25, MooseX::Declare provides some nice sugar for\n that. This is what it looks like:\n\n lang:Perl use MooseX::Declare;\n\n role Counter (Str :$name) { has $name => (is => 'rw', isa => 'In-\n t', default => 0);\n\n method \"increment_${name}\" { $self->$name( $self->$name + 1 ); }\n\n method \"reset_${name}\" { $self->$name(0); } }\n\n class MyGame::Weapon { with Counter => { name => 'enchant-\n ment' }; }\n\n class MyGame::Wand { with Counter => { name => 'zapped' }; }\n\n Just thought I'd let you know, since i haven't gotten around to ac-\n tually document this. In case you like it, have some spare tuits,\n and want to help out, the repository is right here :-)\n" title: Parameterized Roles with MooseX::Declare type: pod uri: http://perldition.org/articles/Parameterized%20Roles%20with%20MooseX%3A%3ADeclare.pod xhtml: "
\n

You've probably already heard of Sartak's awesome\nMooseX::Role::Parameterized.

\n

As of version 0.25, MooseX::Declare provides some nice sugar for\nthat. This is what it looks like:

\n
use MooseX::Declare;\n\nrole Counter (Str :$name) {\n  has $name => (is => 'rw', isa => 'Int', default => 0);\n\n  method "increment_${name}" {\n    $self->$name( $self->$name + 1 );\n  }\n\n  method "reset_${name}" {\n    $self->$name(0);\n  }\n}\n\nclass MyGame::Weapon {\n  with Counter => { name => 'enchantment' };\n}\n\nclass MyGame::Wand {\n  with Counter => { name => 'zapped' };\n}\n
\n

Just thought I'd let you know, since i haven't gotten around to\nactually document this. In case you like it, have some spare\ntuits, and want to help out, the repository is\nright here :-)

\n\n\n
"