I have a default base class, call it My::Moose::Object, that inherits from Moose::Object and adds a few common methods for our application. I want all the objects in my application to inherit from My::Moose::Object.

In a Moose-ish way, I'd like to create a My::Moose that acts like Moose except that the default superclass is My::Moose::Object. Then my classes can be defined like:

    package My::Person;
use My::Moose; # automatically sets superclass to My::Moose::Object, instead of Moose::Object

My::Moose would then be a good place to insert other application-wide Moose changes later on.

But I can't figure out how to implement this. Moose.pm performs all its operations on caller(); so as soon as I create a dummy My::Moose:

   package My::Moose;
   use base qw(Moose);

   sub import
   {
       my ($class) = @_;
       $class->SUPER::import();
       # Do app-specific things here
   }

   1;

then My::Person doesn't work, because Moose::import() thinks the caller is My::Moose.

One solution is for Moose to provide an import_to_class, just like import but taking a classname.

Or perhaps I could use Moose::Policy for this. But then each class would read

    package My::Person;
    use Moose::Policy 'My::Moose::Policy';
    use Moose;

Yuck. It seems like a significant blow to the syntactic single-use- line beauty of Moose, and a violation of DRY.

Maybe I'm just saying that I wish project-wide Policies could be set with a little less syntax, and less room for user error. It seems like it shouldn't be so hard to make this possible.

Jon

Reply via email to