Merge branch 'master' into topic/strict_export_list
Dave Rolsky [Mon, 7 Sep 2009 16:58:50 +0000 (11:58 -0500)]
Conflicts:
t/050_metaclasses/012_moose_exporter.t

1  2 
Changes
lib/Moose/Exporter.pm
t/010_basics/022_moose_exporter_groups.t
t/050_metaclasses/012_moose_exporter.t

diff --cc Changes
Simple merge
@@@ -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,
                  \&{ $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,
  
              $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;
index 589883a,b3cca46..ef69fb2
mode 100755,100644..100644
@@@ -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 };
      }
@@@ -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;
  }
  
  
  }
  
  {
 +    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 );
  }