Re: Moose hook

[email protected] (Peter Gordon)
Newsgroups perl.moose
Message-ID <1318958819.2884.24.camel@qed>
When MyRole is composed into a class.

I want it to fiddle with the attributes of the class while it is being
built.

On Tue, 2011-10-18 at 11:41 -0400, Chris Prather wrote:
> On Tue, Oct 18, 2011 at 11:02 AM, Peter Gordon <[email protected]> wrote:
> > This is the example I am working with:
> >
> > package MyRole ;
> > with Moose::Role ;
> >
> > # Operate on the 'has' items
> > sub runMe {
> > }
> >
> > package X ;around BUILD => \&runMe;
> > use Moose ;
> > has 'item' => ( is => 'rw' , isa => 'Str') ;
> >
> >
> > package Y ;
> > use Moose ;
> > extends 'X' ;
> > with 'MyRole';
> >
> >
> > I would like to be able to define package MyRole such that when it is
> > invoked, runMe() gets run automatically without having to run
> > it explicitly in package Y.
> 
> How do you mean "invoked"? Do you mean when an object is created from
> a class that composes MyRole?
> 
> package MyRole;
> use Moose::Role;
> 
> sub BUILD { }
> around BUILD => \&runMe;
> 
> 
> If you mean when MyRole is composed into a class, that's different.
> 
> -Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.