develooper Front page | perl.moose | Postings from March 2009

Re: triggers and the single meta-attr object

Thread Previous | Thread Next
From:
Hans Dieter Pearcey
Date:
March 29, 2009 18:19
Subject:
Re: triggers and the single meta-attr object
Message ID:
20090329195935.GH3018@glaive.weftsoar.net
On Sun, Mar 29, 2009 at 11:40:43AM -0400, Stevan Little wrote:
> Personally, I don't think we need to pass that meta-attribute, if you  
> really want/need it, then you can do this:
>
> trigger => sub {
>     my $self = shift;
>     $self->meta->find_attribute_by_name('foo')->...
>     ...
> }
>
> The only tricky part of the above workaround is that you need to know  
> the name of the attribute in order to get the meta-attribute. But this  
> shouldn't be too hard to fix/work-around in most cases.

What about passing in the attribute name instead of the meta-attribute?  Then
there's no trickery necessary at all.  Or a coderef that wraps up getting the
necessary objects:

  sub { Moose::Util::find_meta($class_name)->get_attribute($attr_name) }

which requires closing over no objects.

hdp.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About