Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Moose role BUILD question

by stvn (Monsignor)
on Mar 24, 2011 at 22:43 UTC ( #895360=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Moose role BUILD question
in thread Moose role BUILD question

The real problem was more in the OPs code. By putting a BUILD method in his role, he would have run into an issue if he tried to compose it into a class which already had a BUILD, because the local class version of a method beats the role version of it. So actually it is not really that your version was bypassing so much as just not using Roles properly. Once a role is composed into a class, it really should be "forgotten" about since all the methods are basically already "copied" into the class.

Additionally, the BUILD method is never really meant to be called by outside-of-Moose-internals code, it is meant to be called by BUILDALL and in a very specific order so that the object is initialized properly. This is all done within the context of inheritance, which is a Class specific thing. Roles do not inherit, which is why we have to do the weird tricks I showed above to hook into BUILD from a role. So while your solution will force the call to Browser::BUILD and it will happen during the BUILD of the consuming class, it is bypassing all that machinery. Currently, the result is the same, but since you are calling things usually only reserved for internals to call, there is a possibility (although very slim) that this might cause issues down the road.

-stvn


Comment on Re^3: Moose role BUILD question

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2014-10-23 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (129 votes), past polls