From: Jesse Luehrs Date: Tue, 15 Sep 2009 05:52:21 +0000 (-0500) Subject: implement passing certain import args to init_meta X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6e36501ce159e4fa4144ba86c5292b31406cbfe5;p=gitmo%2FMoose.git implement passing certain import args to init_meta --- diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index 8ed1de3..2672e41 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -61,7 +61,8 @@ sub build_import_methods { $exporting_package, $exporter, \@exports_from, - $is_reexport + $is_reexport, + ($args{init_meta_params} || []), ); $methods{unimport} = $class->_make_unimport_sub( @@ -308,6 +309,7 @@ sub _make_import_sub { my $exporter = shift; my $exports_from = shift; my $is_reexport = shift; + my $init_meta_params = shift; return sub { @@ -344,6 +346,16 @@ sub _make_import_sub { strict->import; warnings->import; + my %extra_args; + # don't want to just force @_ into a hash, since it really actually is + # an array + for my $i (1..$#_) { + if (grep { $_ eq $_[$i] } @$init_meta_params) { + $extra_args{$_[$i]} = $_[$i + 1]; + splice @_, $i, 2; + } + } + my $did_init_meta; for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) { @@ -351,7 +363,11 @@ sub _make_import_sub { # Moose::Exporter, which in turn sets $CALLER, so we need # to protect against that. local $CALLER = $CALLER; - $c->init_meta( for_class => $CALLER, metaclass => $metaclass ); + $c->init_meta( + %extra_args, + for_class => $CALLER, + metaclass => $metaclass, + ); $did_init_meta = 1; } diff --git a/t/050_metaclasses/031_new_exporter_parameters.t b/t/050_metaclasses/031_new_exporter_parameters.t index b9173c9..80b780d 100644 --- a/t/050_metaclasses/031_new_exporter_parameters.t +++ b/t/050_metaclasses/031_new_exporter_parameters.t @@ -1,8 +1,7 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More skip_all => "not implemented yet"; -#use Test::More tests => 4; +use Test::More tests => 4; my @init_meta_args; @@ -51,13 +50,6 @@ BEGIN { ); } -is_deeply(\@init_meta_args, [ - { - for_class => 'My::Moose::User', - metaclass => 'Moose::Meta::Class' - } -], "attribute wasn't passed in yet"); - ok(My::Moose::User->meta->get_attribute('counter')->has_accessor, 'our exported sugar works'); { @@ -69,13 +61,11 @@ ok(My::Moose::User->meta->get_attribute('counter')->has_accessor, 'our exported }; } -is_deeply(\@init_meta_args, [ - { - for_class => 'My::Other::Moose::User', - metaclass => 'Moose::Meta::Class' - attribute => 'counter', - } -], "got attribute in our init_meta params"); +ok(My::Moose::User->meta->get_attribute('counter')->has_accessor, 'our extra exporter option worked'); +ok(!exists $init_meta_args[0]->{attribute}, + "attribute wasn't passed in yet"); + +is($init_meta_args[1]->{attribute}, 'counter', + "got attribute in our init_meta params"); -ok(My::Moose::User->meta->get_attribute('counter')->has_accessor, 'our extra exporter option worked');