X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FExporter.pm;h=3cbd81e8fb492ecb660c13c3e7ea9b517d63bdd4;hp=639b044494ebd3fc5c54d447c850d77784fc4bb1;hb=e57a5068a04271a23b54f834ddec60e82b76275e;hpb=72dc2c9d7f309b7e9216cdc7ab0e30feb0f2edd8 diff --git a/lib/Mouse/Exporter.pm b/lib/Mouse/Exporter.pm index 639b044..3cbd81e 100644 --- a/lib/Mouse/Exporter.pm +++ b/lib/Mouse/Exporter.pm @@ -6,14 +6,15 @@ use Carp qw(confess); my %SPEC; -use constant _strict_bits => strict::bits(qw(subs refs vars)); +my $strict_bits; +BEGIN{ $strict_bits = strict::bits(qw(subs refs vars)); } # it must be "require", because Mouse::Util depends on Mouse::Exporter, # which depends on Mouse::Util::import() require Mouse::Util; sub import{ - $^H |= _strict_bits; # strict->import; + $^H |= $strict_bits; # strict->import; ${^WARNING_BITS} |= $warnings::Bits{all}; # warnings->import; return; } @@ -26,20 +27,24 @@ sub setup_import_methods{ my($import, $unimport) = $class->build_import_methods(%args); - no strict 'refs'; - - *{$exporting_package . '::import'} = $import; - *{$exporting_package . '::unimport'} = $unimport; - - # for backward compatibility - *{$exporting_package . '::export_to_level'} = sub{ - my($package, $level, undef, @args) = @_; # the third argument is redundant - $package->import({ into_level => $level + 1 }, @args); - }; - *{$exporting_package . '::export'} = sub{ - my($package, $into, @args) = @_; - $package->import({ into => $into }, @args); - }; + Mouse::Util::install_subroutines($exporting_package, + import => $import, + unimport => $unimport, + + export_to_level => sub { + my($package, $level, undef, @args) = @_; # the third argument is redundant + + Carp::carp("$package->export_to_level has been deprecated." + ." Use $package->import({ into_level => LEVEL }) instead"); + $package->import({ into_level => $level + 1 }, @args); + }, + export => sub { + my($package, $into, @args) = @_; + Carp::carp("$package->export has been deprecated." + ." Use $package->import({ into => PACKAGE }) instead"); + $package->import({ into => $into }, @args); + }, + ); return; } @@ -85,9 +90,9 @@ sub build_import_methods{ ($code_package, $code_name) = Mouse::Util::get_code_info($code); } else{ - no strict 'refs'; $code_package = $package; $code_name = $thingy; + no strict 'refs'; $code = \&{ $code_package . '::' . $code_name }; } @@ -163,7 +168,7 @@ sub do_import { } } - $^H |= _strict_bits; # strict->import; + $^H |= $strict_bits; # strict->import; ${^WARNING_BITS} |= $warnings::Bits{all}; # warnings->import; if($spec->{INIT_META}){ @@ -194,18 +199,17 @@ sub do_import { } if(@exports){ + my @export_table; foreach my $keyword(@exports){ - no strict 'refs'; - *{$into.'::'.$keyword} = $spec->{EXPORTS}{$keyword} - || confess(qq{The $package package does not export "$keyword"}); + push @export_table, + $keyword => ($spec->{EXPORTS}{$keyword} + || confess(qq{The $package package does not export "$keyword"}) + ); } + Mouse::Util::install_subroutines($into, @export_table); } else{ - my $default = $spec->{DEFAULT}; - while(my($keyword, $code) = each %{$default}){ - no strict 'refs'; - *{$into.'::'.$keyword} = $code; - } + Mouse::Util::install_subroutines($into, %{$spec->{DEFAULT}}); } return; }