Merge branch 'master' into topic/strict_export_list
[gitmo/Moose.git] / lib / Moose / Exporter.pm
index 42c7dac..26eaa11 100644 (file)
@@ -37,14 +37,14 @@ sub build_import_methods {
 
     my $export_recorder = {};
 
-    my ( $exports, $is_removable, $groups )
+    my ( $exports, $is_removable )
         = $class->_make_sub_exporter_params(
         [ @exports_from, $exporting_package ], $export_recorder );
 
     my $exporter = Sub::Exporter::build_exporter(
         {
             exports => $exports,
-            groups  => { default => [':all'], %$groups }
+            groups  => { default => [':all'] }
         }
     );
 
@@ -119,7 +119,6 @@ sub _make_sub_exporter_params {
     my $packages          = shift;
     my $export_recorder   = shift;
 
-    my %groups;
     my %exports;
     my %is_removable;
 
@@ -127,16 +126,7 @@ sub _make_sub_exporter_params {
         my $args = $EXPORT_SPEC{$package}
             or die "The $package package does not use Moose::Exporter\n";
 
-        # one group for each 'also' package
-        $groups{$package} = [
-            @{ $args->{with_caller} || [] },
-            @{ $args->{with_meta}   || [] },
-            @{ $args->{as_is}       || [] },
-            map ":$_",
-            keys %{ $args->{groups} || {} }
-        ];
-
-        for my $name ( @{ $args->{with_caller} } ) {
+        for my $name ( @{ $args->{with_meta} } ) {
             my $sub = do {
                 no strict 'refs';
                 \&{ $package . '::' . $name };
@@ -150,7 +140,7 @@ sub _make_sub_exporter_params {
 
             my $fq_name = $package . '::' . $name;
 
-            $exports{$name} = $class->_make_wrapped_sub(
+            $exports{$name} = $class->_make_wrapped_sub_with_meta(
                 $fq_name,
                 $sub,
                 $export_recorder,
@@ -159,7 +149,7 @@ sub _make_sub_exporter_params {
             $is_removable{$name} = 1;
         }
 
-        for my $name ( @{ $args->{with_meta} } ) {
+        for my $name ( @{ $args->{with_caller} } ) {
             my $sub = do {
                 no strict 'refs';
                 \&{ $package . '::' . $name };
@@ -173,7 +163,7 @@ sub _make_sub_exporter_params {
 
             my $fq_name = $package . '::' . $name;
 
-            $exports{$name} = $class->_make_wrapped_sub_with_meta(
+            $exports{$name} = $class->_make_wrapped_sub(
                 $fq_name,
                 $sub,
                 $export_recorder,
@@ -224,26 +214,9 @@ sub _make_sub_exporter_params {
 
             $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;
@@ -635,14 +608,15 @@ Moose::Exporter - make an import() and unimport() just like Moose.pm
   use Moose::Exporter;
 
   Moose::Exporter->setup_import_methods(
-      with_caller => [ 'has_rw', 'sugar2' ],
-      as_is       => [ 'sugar3', \&Some::Random::thing ],
-      also        => 'Moose',
+      with_meta => [ 'has_rw', 'sugar2' ],
+      as_is     => [ 'sugar3', \&Some::Random::thing ],
+      also      => 'Moose',
   );
 
   sub has_rw {
-      my ($caller, $name, %options) = @_;
-      Class::MOP::class_of($caller)->add_attribute($name,
+      my ( $meta, $name, %options ) = @_;
+      $meta->add_attribute(
+          $name,
           is => 'rw',
           %options,
       );
@@ -705,12 +679,13 @@ This method accepts the following parameters:
 
 =over 8
 
-=item * with_caller => [ ... ]
+=item * with_meta => [ ... ]
 
 This list of function I<names only> will be wrapped and then exported. The
-wrapper will pass the name of the calling package as the first argument to the
-function. Many sugar functions need to know their caller so they can get the
-calling package's metaclass object.
+wrapper will pass the metaclass object for the caller as its first argument.
+
+Many sugar functions will need to use this metaclass object to do something to
+the calling package.
 
 =item * as_is => [ ... ]
 
@@ -728,7 +703,7 @@ to keep it.
 This is a list of modules which contain functions that the caller
 wants to export. These modules must also use C<Moose::Exporter>. The
 most common use case will be to export the functions from C<Moose.pm>.
-Functions specified by C<with_caller> or C<as_is> take precedence over
+Functions specified by C<with_meta> or C<as_is> take precedence over
 functions exported by modules specified by C<also>, so that a module
 can selectively override functions exported by another module.