views:

66

answers:

1

I've made a "bundle" module which does a bunch of things: imports Moose, imports true, namespace::autoclean, makes the caller's class immutable (taken from MooseX::AutoImmute). The one thing I haven't been able to figure out is how to include MooseX::Method::Signatures.

Here's what I've got so far:

package My::OO;

use Moose::Exporter;
use Hook::AfterRuntime;

use Moose ();
use true ();
use namespace::autoclean ();

my ($import, $unimport, $init_meta) = Moose::Exporter->build_import_methods(
 also => ['Moose'],
);
sub import {
 true->import();

 my $caller = scalar caller;
 after_runtime { $caller->meta->make_immutable };

 namespace::autoclean->import(-cleanee => $caller);

 goto &$import;
}
sub unimport {
 goto &$unimport;
}

1;

The idea is that in my code, I can now do things like this:

package My::Class; {
    use My::OO;
    extends 'My::Parent';
    method foo() { ... }
}

but right now I still have to include an extra use MooseX::Method::Signatures;. How can I include that into my OO module?

+10  A: 

First off, please note that the implementation of Hook::AfterRuntime is quite fragile. While it works for many simple things, it's extremely easy to end up with very hard to debug errors. I'd recommend just writing the ->meta->make_immutable yourself, or using other approaches to get around writing it, like MooseX::Declare, for example.

To answer your actual question:

MooseX::Method::Signatures->setup_for($your_caller);
rafl