in reply to Moose: Importing methods via Traits

You could use a Role:

package DoesBubba; use Moose::Role; sub bubba { ... } 1;

Then in your class:

package Hubba; use Moose; with 'DoesBubba'; # rest of your class here.

The 'bubba' method will be composed into your 'Hubba' class (and any other that consumes this role).

Replies are listed 'Best First'.
Re^2: Moose: Importing methods via Traits
by morgon (Priest) on Apr 27, 2009 at 21:58 UTC
    You could use a Role
    Ok, maybe I made myself not clear.

    I do not want a method on the Hubba-class that would be available to it's instances, but I want a method on it that I can call (in the same way as let's say the Moose-supplied method "has" is called) at package-load time to associate a class with a piece of information.

    As an example think about the name of a database-table where instances of this class will get persisted as in Moose::Cookbook::Meta::Recipe5.

    My question then is simply is there a way to avoid the uglyness (in my eyes at least) of doing something like " __PACKAGE__->meta->table('User')"