X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDevel%2FDeclare%2FMethodInstaller%2FSimple.pm;h=0bf0e9f1b2d290a406bc30aad2f37d6bdc820c84;hb=5c82d5478de9d26a18ff812912b91b9170126b31;hp=911fa5341fdd057a678d754b1257c534f7826870;hpb=f00d48a3a7bae27a9559845f1f6e87dff73792c2;p=p5sagit%2FDevel-Declare.git diff --git a/lib/Devel/Declare/MethodInstaller/Simple.pm b/lib/Devel/Declare/MethodInstaller/Simple.pm index 911fa53..0bf0e9f 100644 --- a/lib/Devel/Declare/MethodInstaller/Simple.pm +++ b/lib/Devel/Declare/MethodInstaller/Simple.pm @@ -7,7 +7,7 @@ use Sub::Name; use strict; use warnings; -our $VERSION = '0.006000'; +our $VERSION = '0.006005'; sub install_methodhandler { my $class = shift; @@ -17,10 +17,11 @@ sub install_methodhandler { *{$args{into}.'::'.$args{name}} = sub (&) {}; } + my $warnings = warnings::enabled("redefine"); my $ctx = $class->new(%args); Devel::Declare->setup_for( $args{into}, - { $args{name} => { const => sub { $ctx->parser(@_) } } } + { $args{name} => { const => sub { $ctx->parser(@_, $warnings) } } } ); } @@ -35,7 +36,11 @@ sub code_for { my $code = shift; # So caller() gets the subroutine name no strict 'refs'; - *{$name} = subname $name => $code; + my $installer = $self->warning_on_redefine + ? sub { *{$name} = subname $name => $code; } + : sub { no warnings 'redefine'; + *{$name} = subname $name => $code; }; + $installer->(); return; }; } else {