From: Dave Rolsky Date: Mon, 7 Sep 2009 16:58:50 +0000 (-0500) Subject: Merge branch 'master' into topic/strict_export_list X-Git-Tag: 0.89_02~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=addd05f659a6c3c2349fac6197a1e94ead0af36f;p=gitmo%2FMoose.git Merge branch 'master' into topic/strict_export_list Conflicts: t/050_metaclasses/012_moose_exporter.t --- addd05f659a6c3c2349fac6197a1e94ead0af36f diff --cc lib/Moose/Exporter.pm index 42c7dac,53f2249..26eaa11 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@@ -142,15 -132,9 +132,15 @@@ sub _make_sub_exporter_params \&{ $package . '::' . $name }; }; + if ( !defined(&$sub) ) { + Carp::cluck + "Trying to export undefined sub ${package}::${name}"; + next; + } + my $fq_name = $package . '::' . $name; - $exports{$name} = $class->_make_wrapped_sub( + $exports{$name} = $class->_make_wrapped_sub_with_meta( $fq_name, $sub, $export_recorder, @@@ -165,15 -149,9 +155,15 @@@ \&{ $package . '::' . $name }; }; + if ( !defined(&$sub) ) { + Carp::cluck + "Trying to export undefined sub ${package}::${name}"; + next; + } + my $fq_name = $package . '::' . $name; - $exports{$name} = $class->_make_wrapped_sub_with_meta( + $exports{$name} = $class->_make_wrapped_sub( $fq_name, $sub, $export_recorder, @@@ -222,28 -192,11 +212,11 @@@ $export_recorder->{$sub} = 1; - $exports{$name} = sub {$sub}; + $exports{$coderef_name} = sub {$sub}; } - - for my $name ( keys %{ $args->{groups} } ) { - my $group = $args->{groups}{$name}; - - if (ref $group eq 'CODE') { - $groups{$name} = $class->_make_wrapped_group( - $package, - $group, - $export_recorder, - \%exports, - \%is_removable - ); - } - elsif (ref $group eq 'ARRAY') { - $groups{$name} = $group; - } - } } - return ( \%exports, \%is_removable, \%groups ); + return ( \%exports, \%is_removable ); } our $CALLER; diff --cc t/010_basics/022_moose_exporter_groups.t index 589883a,b3cca46..ef69fb2 mode 100755,100644..100644 --- a/t/010_basics/022_moose_exporter_groups.t +++ b/t/010_basics/022_moose_exporter_groups.t @@@ -77,22 -92,25 +92,27 @@@ use Test::Exception also => ['ExGroups1'], as_is => ['exgroups2_as_is'], with_caller => ['exgroups2_with_caller'], - groups => { default => ['exgroups2_as_is'], - code_group => \&generate_group, - parent1 => [qw(:ExGroups1 :code_group)], - parent2 => [qw(:all)] } + groups => { + default => ['exgroups2_as_is'], + code_group => \&generate_group, + parent1 => [qw(:ExGroups1 :code_group)], + parent2 => [qw(:all)] + } ); - sub exgroups2_as_is { 3 } + sub exgroups2_as_is {3} + sub exgroups2_with_caller { 4 } + sub generate_group { - my ($caller, $group_name, $args, $context) = @_; + my ( $caller, $group_name, $args, $context ) = @_; - ::is($group_name, 'code_group', 'original name is passed to group code'); - ::is($args->{install_as}, $caller . '_code', 'group code arguments match caller'); - ::is($context->{from}, __PACKAGE__, 'defined package name is passed to group code'); + ::is( $group_name, 'code_group', + 'original name is passed to group code' ); + ::is( $args->{install_as}, $caller . '_code', + 'group code arguments match caller' ); + ::is( $context->{from}, __PACKAGE__, + 'defined package name is passed to group code' ); return { $args->{install_as} => \&exported_by_group }; } diff --cc t/050_metaclasses/012_moose_exporter.t index 52aabf2,ef9db42..41cd0f6 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@@ -8,7 -8,7 +8,7 @@@ use Test::Exception BEGIN { eval "use Test::Output;"; plan skip_all => "Test::Output is required for this test" if $@; - plan tests => 49; - plan tests => 63; ++ plan tests => 65; } @@@ -292,24 -292,75 +292,96 @@@ } { + package NonExistentExport; + + use Moose (); + + ::stderr_like { + Moose::Exporter->setup_import_methods( + also => ['Moose'], + with_caller => ['does_not_exist'], + ); + } qr/^Trying to export undefined sub NonExistentExport::does_not_exist/, + "warns when a non-existent method is requested to be exported"; +} + +{ + package WantsNonExistentExport; + + NonExistentExport->import; + + ::ok(!__PACKAGE__->can('does_not_exist'), + "undefined subs do not get exported"); ++ + package AllOptions; + use Moose (); + use Moose::Exporter; + + Moose::Exporter->setup_import_methods( + also => ['Moose'], + with_meta => [ 'with_meta1', 'with_meta2' ], + with_caller => [ 'with_caller1', 'with_caller2' ], + as_is => ['as_is1'], + ); + + sub with_caller1 { + return @_; + } + + sub with_caller2 (&) { + return @_; + } + + sub as_is1 {2} + + sub with_meta1 { + return @_; + } + + sub with_meta2 (&) { + return @_; + } + } + + { + package UseAllOptions; + + AllOptions->import(); + } + + { + can_ok( 'UseAllOptions', $_ ) + for qw( with_meta1 with_meta2 with_caller1 with_caller2 as_is1 ); + + { + my ( $caller, $arg1 ) = UseAllOptions::with_caller1(42); + is( $caller, 'UseAllOptions', 'with_caller wrapped sub gets the right caller' ); + is( $arg1, 42, 'with_caller wrapped sub returns argument it was passed' ); + } + + { + my ( $meta, $arg1 ) = UseAllOptions::with_meta1(42); + isa_ok( $meta, 'Moose::Meta::Class', 'with_meta first argument' ); + is( $arg1, 42, 'with_meta1 returns argument it was passed' ); + } + + is( + prototype( UseAllOptions->can('with_caller2') ), + prototype( AllOptions->can('with_caller2') ), + 'using correct prototype on with_meta function' + ); + + is( + prototype( UseAllOptions->can('with_meta2') ), + prototype( AllOptions->can('with_meta2') ), + 'using correct prototype on with_meta function' + ); + + { + package UseAllOptions; + AllOptions->unimport(); + } + + ok( ! UseAllOptions->can($_), "UseAllOptions::$_ has been unimported" ) + for qw( with_meta1 with_meta2 with_caller1 with_caller2 as_is1 ); }