morgon has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to sweeten some classes with a spoonful of syntactic sugar and wonder if it is possible (and how :-) to achieve the following in Moose:
So what I want is a trait that implements a method ("bubba") and imports this method into the namespace of every class that uses this trait.package Hubba; use Moose -traits => 'WithBubba'; has a; has b; bubba "zappa"; # <- this method should be imported
Evidently I could use something like
But I find that ugly ... is there a nicer way?__PACKAGE__->meta->bubba("zappa");
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose: Importing methods via Traits
by bruno (Friar) on Apr 27, 2009 at 17:56 UTC | |
by morgon (Priest) on Apr 27, 2009 at 21:58 UTC | |
|
Re: Moose: Importing methods via Traits
by KSURi (Monk) on Apr 27, 2009 at 19:18 UTC | |
by morgon (Priest) on Apr 28, 2009 at 17:00 UTC |