Is there a way to override the constructor in Moo?

886 views Asked by At

I am working on a MooX module that needs to add a wrapper around the constructor.

I've tried method modifies or having the import method directly change *{"${target}::new"} with no effect.

So how can I do this?

1

There are 1 answers

0
Rob On BEST ANSWER

Apparently, around does work:

package MyRole;
use Moo::Role

around new => sub { ... };

but the role that has the around needs to be consumed after attributes are added, e.g.

package MyClass;
use Moo;

has attr1 => (... );
with 'MyRole';