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
+ $package->import({ into_level => $level + 1 }, @args);
+ },
+ export => sub {
+ my($package, $into, @args) = @_;
+ $package->import({ into => $into }, @args);
+ },
+ );
return;
}
($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 };
}
}
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;
}
my $predicate = sub{ Scalar::Util::blessed($_[0]) && $_[0]->isa($for_class) };
if(defined $name){
- no strict 'refs';
- *{ caller() . '::' . $name } = $predicate;
+ Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
return;
}
};
if(defined $name){
- no strict 'refs';
- *{ caller() . '::' . $name } = $predicate;
+ Mouse::Util::install_subroutines(scalar caller, $name => $predicate);
return;
}
$self->{methods}->{$name} = $code; # Moose stores meta object here.
- my $pkg = $self->name;
- no strict 'refs';
- no warnings 'redefine', 'once';
- *{ $pkg . '::' . $name } = $code;
+ Mouse::Util::install_subroutines($self->name,
+ $name => $code,
+ );
return;
}
sub get_linear_isa($;$); # must be here
+sub install_subroutines { # must be here
+ my $into = shift;
+
+ while(my($name, $code) = splice @_, 0, 2){
+ no strict 'refs';
+ no warnings 'once', 'redefine';
+ use warnings FATAL => 'uninitialized';
+ *{$into . '::' . $name} = \&{$code};
+ }
+ return;
+}
+
BEGIN{
# This is used in Mouse::PurePerl
Mouse::Exporter->setup_import_methods(