Re: "automatically" wrapping methods.

[email protected] (Jesse Luehrs)
Newsgroups perl.moose
Message-ID <[email protected]>
On Wed, Jan 11, 2012 at 01:58:40PM -0800, Peter Shangov wrote:
> Or you can use B::Hooks::EndOfScope to do the wrapping at the end of the compilation stage:
> 
> # untested code
> package MooseX::MethodValidation;
> use B::Hooks::EndOfScope;
> sub import {
>   on_scope_end {
>     my $caller = caller;
>     my $meta = Moose::Meta::Class->initialize($caller);
>     foreach my $method ( $meta->get_all_methods )  {
>       ... # wrapping code goes here
>     }
>   }
> }
> 
> package MyModel::User;
> use MooseX::MethodValidation;
> ... # your subs go here

This actually isn't a great idea, because not all methods are defined at
compile time. If you declare any methods via method modifiers, or
attributes, or any other method declaration sugar, they won't exist when
that validation code runs.

-doy
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.