| 1 | package MooseX::DeclareX::Plugin::imports; | ||
| 2 | |||
| 3 | BEGIN { | ||
| 4 | $MooseX::DeclareX::Plugin::imports::AUTHORITY = 'cpan:TOBYINK'; | ||
| 5 | $MooseX::DeclareX::Plugin::imports::VERSION = '0.009'; | ||
| 6 | } | ||
| 7 | |||
| 8 | use Moose; | ||
| 9 | with 'MooseX::DeclareX::Plugin'; | ||
| 10 | |||
| 11 | use MooseX::Declare (); | ||
| 12 | use Moose::Util (); | ||
| 13 | use Data::OptList; | ||
| 14 | use Data::Dumper; | ||
| 15 | |||
| 16 | sub plugin_setup | ||
| 17 | { | ||
| 18 | my ($class, $kw, $opt) = @_; | ||
| 19 | $opt = Data::OptList::mkopt($opt); | ||
| 20 | |||
| 21 | local $Data::Dumper::Terse = 1; | ||
| 22 | local $Data::Dumper::Indent = 0; | ||
| 23 | my @codeparts = map { | ||
| 24 | my ($module, $terms) = @$_; | ||
| 25 | $terms = [] unless defined $terms; | ||
| 26 | confess "parameters for $module must be an arrayref" | ||
| 27 | unless ref $terms eq 'ARRAY'; | ||
| 28 | sprintf('use %s @{%s}', $module, Dumper $terms); | ||
| 29 | } @$opt; | ||
| 30 | |||
| 31 | $kw->meta->add_after_method_modifier( | ||
| 32 | add_namespace_customizations => sub { | ||
| 33 | my ($self, $ctx, $package) = @_; | ||
| 34 | $ctx->add_preamble_code_parts(@codeparts); | ||
| 35 | }, | ||
| 36 | ); | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 |