Actually this code has a problem, if your class has a BUILD method in it, then the role method will never get consumed. ikegami's solution will fix it for you, but it bypasses the nice aspects that BUILD and the BUILDALL method that calls it.
Instead I suggest the more common Moose idiom which is to use method-modifiers with roles and BUILD, so your Browser role would look more like:
This will then work with classes which do not have an existing BUILD (by installing the empty one in the role) and ones which have an existing BUILD (local class beats role in composition, but the after modifier will always get applied).package Browser; our $VERSION=0.01; use Moose::Role; requires qw(cookieCreate cookieDelete navigation); sub BUILD {} after 'BUILD' => sub { my $self = shift; $self->cookieCreate; };
In reply to Re: Moose role BUILD question
by stvn
in thread Moose role BUILD question
by saintex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |