On Wed, Apr 28, 2010 at 12:59:21PM +0100, Zbigniew Lukasiak wrote:
> Hi there,
>
> The recipe in
> http://search.cpan.org/~flora/Moose-1.01/lib/Moose/Cookbook/Meta/Recipe3.pod
> uses an additional package in the Moose namespace:
>
> package Moose::Meta::Attribute::Custom::Trait::Labeled;
> sub register_implementation {'MyApp::Meta::Attribute::Trait::Labeled'}
>
> Forgive my ignorance - I am just starting to learn this stuff - but is
> there a way to not use a package in the Moose namespace for this? I
> mean if I add a package like that to my distribution - then I can
> expect some problems with permissions to the Moose namespace on CPAN
> (if not now - then in the future), and also it can easily lead to name
> collisions.
>
> To give you some context: the full example of what I am doing is at: (
> http://github.com/zby/WebNano/tree/master/lib/Moose/Meta/Class/Custom/Trait/,
> http://github.com/zby/WebNano/blob/master/lib/WebNano/Controller/Meta/Class/Trait/WebDispatchTable.pm
> and
> http://github.com/zby/WebNano/blob/master/lib/WebNano/Controller/WebDispatchTable/Moose.pm)
> in short it adds a 'get' keyword that register a sub on a dispatch
> table kept in the meta class.
Usually in the past, you would just define this package inside the file
that defines your trait:
package Foo::Meta::Trait;
use Moose::Role;
...;
package # hide from PAUSE
Moose::Meta::Attribute::Custom::Trait::Foo;
sub register_implementation { 'Foo::Meta::Trait' }
With recent Moose versions though, you can just do this:
package Foo::Meta::Trait;
use Moose::Role;
Moose::Util::meta_attribute_alias('Foo');
...;
-doy