Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Abstract class under MooseX-Declare

by greengaroo (Hermit)
on Aug 09, 2012 at 21:15 UTC ( #986613=note: print w/ replies, xml ) Need Help??


in reply to Re: Abstract class under MooseX-Declare
in thread Abstract class under MooseX-Declare

First, thank you very much for your input, I really appreciate it.

Let me answer your second statement first, about putting the exception in the constructor instead of the BUILD method. According to Moose best practices: Overriding new is a very bad practice. Instead, you should use a BUILD or BUILDARGS methods to do the same thing. When you override new, Moose can no longer inline a constructor when your class is immutabilized. So this is basically why I don't use it in the constructor.

Now, why I use the BUILD method is because in Moose, the BUILD methods are called in order from the parent to the child, and not the other way around like normal methods. So instantiating the Abstract Class itself would trigger the call of its own BUILD method first, throwing an exception right away without executing more code.

So, for an Abstract Class child of the first one, I would probably have to put an exact copy of the BUILD method I used in my example to prevent this child class from being instantiated too. Its BUILD method would be called in second place, just after its parent's.

-- Take my advice. I don't use it anyway.


Comment on Re^2: Abstract class under MooseX-Declare

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986613]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-12-27 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls