Hi Stevan,

Of course I could always roll back to the stock perl way, but I always prefer 
to let the moose do the work.

For parameterized types, there is no way to delegate into the caller the 
parameterized instances, and in this case, I don't really need to make the 
'actions' attribute a class.  However it would be nice to use the method 
modifiers (MM) for the parameterized type (in this case CodeRef, but it could 
be in principle any type, example, the Array MM) in the class via handles{}.

Since the methods delegated by the MM need to be have unique names, it would 
need to use some API to do this passing in args in the same way as handles{} 
takes care of it.

Such that I can say (this is all very rough pseudo code):

has 'actions' => (
        traits                  => ['Hash'],
        is                      => 'rw', 
        isa                     => 'HashRef[CodeRef]',  
        required                => 0,
        handles   => {
          my_set_actions        => 'set',
          get_actions           => 'get',
      },
);


sub my_set_action {
        my ($self, $name, $value)=...@_;
        
        $self->set_actions($name, $value);
 
        # do some api call to load the method modifiers in 
Moose::Meta::Attribute::Native::Trait::Code
        #  into $self (with unique method names of course)
        # e.g. 
        My %foo = (
          my_execute            => 'execute',
          my_execute_method     => 'execute_method',
        )

        Class::MOP::blah:blah::delegate_my_mm_into_this_object->($self, 
$self->gt_actions($name), $foo)

        ...             
        
}



sub bar {
...

$self->my_execute()

...


}


In hindsight this looks messy and nasty to me.

br


-----Original Message-----
From: Stevan Little [mailto:[email protected]] 
Sent: Tuesday, August 03, 2010 12:20 PM
To: Brian ROONEY
Cc: [email protected]
Subject: Re: parameterized Helper traits


On Aug 3, 2010, at 4:21 AM, Brian ROONEY wrote:
> Thanks Nick,
>
> It's actually the delegation of the helpers for CodeRef i'm unsure  
> how to use since they are wrapped in the Hash, I would imagine I  
> would have to use some API call similar to what 'handles' does to  
> pull the execute() and execute_method() method modifiers in  
> Moose::Meta::Attribute::Native::Trait::Code into my class each time  
> a new item is added to the Hash.
>
> sub my_set_actions {
>       my ($self)=...@_;
>
>       # allocate new CodeRef
>
>       # add it to the Hash
>
>       # do some api call to load the method modifiers in  
> Moose::Meta::Attribute::Native::Trait::Code
>       #  into $self (with unique method names of course)
>               
>       $self->set_actions('Baz', $coderef )
> }

No, there is no support for this in plain Moose. However, I suspect it  
could be accomplished with a bit of metaprogramming.

Can you be more clear about what it is you want it to actually do in  
the end? At this point I am not quite sure what you are looking for in  
terms of an API to call the coderefs in your hash, and why $obj- 
 >get_action('Foo')->() is not sufficient.

- Stevan

Reply via email to