Re: method as trigger
[email protected] (Stevan Little)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Christoph,
I don't see any reason why trigger couldn't also take a method name
as well as a CODE ref.
However, in your example below, you pass $_[2] into &change, where $_
[2] is the attribute metaobject for
'pub_in_a_TkObjectsModel_Instance'. This would not be the common
behavior most people would expect I think.
I would be more inclined to do something like:
trigger => 'changed'
then trigger would be expanded into this by Moose:
trigger => sub { (shift)->changed(@_) }
which may or may not always do what you want.
I think Matt Trout may have already implemented a similar feature in
Reaction.
- Stevan
On Jun 4, 2007, at 5:25 PM, Ch Lamprecht wrote:
> Hello,
>
> I was trying to use a method of my class as 'trigger' in an
> attributes definition. Here is what I wrote:
>
> has pub_in_a_TkObjectsModel_Instance => ( isa => 'TkObjectsModel',
> is => 'rw',
> trigger => sub{$_[0] ->
> changed($_[2])},
> );
>
> That works fine. However, are there more elegant solutions?
> Wouldn't it be a nice feature, if we could say:
>
> ...
> trigger => 'changed',
> ...
>
> (Like in a Perl-Tk callback definition)?
>
> Christoph