[Catalyst] More natural access to model?
Paweł Tęcza
ptecza at uw.edu.pl
Tue May 12 13:15:03 GMT 2009
Tomas Doran pisze:
> Paweł Tęcza wrote:
>> Thank you very much for your response! Is it a way to autogenerate all
>> necessary subroutines in a loop or I need define all of them manually?
>> They should have very similar body :)
>
> Here is the gross method:
>
> no strict 'refs';
> foreach my $name (qw/ method_one method_two /) {
> *{$name} = sub {
> my $self = shift;
> # Your code here
> };
> }
>
>
> I'd instead recommend using Moose to do it for you:
>
> use Moose;
> foreach my $name (qw/ method_one method_two /) {
> __PACKAGE__->meta->add_method($name, sub {
> my $self = shift;
> # Your code here
> };
> }
>
> This is (a) less icky, and (b) means that your generated code will come
> out nicely in stack traces / error reports, rather than being 'ANON'.
Hi Tom,
Perl is great! Thanks a lot for these methods! It's very helpful for me.
I'm your debtor now ;)
My best regards,
P.
More information about the Catalyst
mailing list