Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Silence redefine warnings in alias() #191

Merged
merged 2 commits into from Apr 29, 2011
Jump to file or symbol
Failed to load files and symbols.
+15 −4
Split
@@ -10,13 +10,15 @@ require Carp;
sub alias {
my $self = shift;
- Carp::croak("Not enough arguments given to alias()") unless @_;
+ Carp::croak('Not enough arguments given to alias()') unless @_;
my @name = @_;
unshift @name, (caller)[0] unless @name > 1 or grep /::/, @name;
- my $name = join "::", @name;
+ my $name = join '::', @name;
+ # If this redefines something, assume the user wanted to
+ no warnings 'redefine';
no strict 'refs';
*{$name} = $self;
return 1;
View
@@ -3,7 +3,7 @@
use perl5i::latest;
use Test::More;
-
+use Test::Warn;
# Test name construction
{
@@ -75,4 +75,13 @@ use Test::More;
}
-done_testing();
+# No redefine warnings:
+{
+ sub egg { 42 }
+ sub ham { 10 }
+ warning_is {
+ (\&egg)->alias('ham');
+ } undef, 'no warning';
+}
+
+done_testing;