Hi!

On Tue, Nov 16, 2010 at 11:32:55AM -0600, Evan Carroll wrote:
> Because a role doesn't have a BUILD people often write `around 'BUILD'
> => sub {}`. If this is to continue, should BUILD be special cased such
> that a role wrapping it can still fire code if it isn't present in the
> composing class? Should the role install BUILD if it isn't present,
> like an `override_or_after 'BUILD' => sub {}`?

I recently had the same question and got this reply on IRC:

11:14 <@domm> hey, I want to init some stuff in a role, but using after 
'BUILD' does not work if the class consuming the role does not have a BUILD 
method. Are there any other ways to init stuff from a role?
11:14 <@mst> sub BUILD {} after BUILD => sub {
11:14 <@mst> remember that a role provides -defaults- for methods
11:15 <@mst> so the class either gets an empty BUILD or keeps its own


i.e. just define a sub BUILD {} in your role. If the consuming class 
also has a BUILD, the classes BUILD will win.

-- 
#!/usr/bin/perl                              http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Reply via email to