Dinosaur has asked for the wisdom of the Perl Monks concerning the following question:
I'm new to Moose. My most recent discovery (the hard way) is that if you have a BUILD method in your class, and also one in a role the class consumes, only the class BUILD gets invoked. Makes sense: it's an override like any other.
So how do I specify in my role processing that should occur when the class is instantiated? Well, I can hack my way around that with attribute builder methods, I suspect.
But I don't know how to (cleanly) do the same for DEMOLISH. Things that occur to me to try include:
Implicitly require that the class invokes the role's DEMOLISH processing. Too easy to forget to do.
'requires DEMOLISH', 'after DEMOLISH' in the role. That at least gets enforced. But it's an additional constraint on the class.
Turn the role into a class, and make the old class a subclass of it. Works in some situations, but not in others.
You get the idea: I want the role to quietly do its thing without imposing its will on the class which consumes it.
TIA for any ideas.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BUILD in Moose role
by stvn (Monsignor) on Apr 28, 2010 at 21:10 UTC | |
by Dinosaur (Beadle) on Apr 29, 2010 at 16:39 UTC | |
|
Re: BUILD in Moose role
by chromatic (Archbishop) on Apr 28, 2010 at 21:06 UTC |