|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Re: Adding a method to an existing objectby draegtun (Scribe) |
| on Feb 17, 2012 at 16:56 UTC ( #954566=note: print w/ replies, xml ) | Need Help?? |
|
The following two modules on CPAN allow you to add methods to an object: * MooseX::SingletonMethod (for Moose objects)* Object::Method (for normal Perl objects) Alternatively in Moose you can apply roles directly to an object: YourRole->meta->apply( $your_object ); # $your_object now has the methods from YourRoleI did a few blog posts on how roles work and howto implement singleton-methods (in Moose). They're listed in the MooseX::SingletonMethod CPAN page. Also this link should bring them up. /I3az/
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||