How do you replace a method of a Moose object at runtime?

Posted by xxxxxxx on Stack Overflow See other posts from Stack Overflow or by xxxxxxx
Published on 2010-03-12T18:13:07Z Indexed on 2010/03/12 22:37 UTC
Read the original article Hit count: 519

Filed under:
|
|
|
|

Is it possible to replace a method of a Moose object at runtime ? By looking at the source code of Class::MOP::Method (which Moose::Meta::Method inherits from) I concluded that by doing

 $method->{body} = sub{ my stuff }

I would be able to replace at runtime a method of an object. I can get the method using

 $object->meta->find_method_by_name(<method_name>);

However, this didn't quite work out.

Is it conceivable to modify methods at run time? And, what is the way to do it with Moose?

© Stack Overflow or respective owner

Related posts about perl

Related posts about moose