X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDevel%2FDeclare%2FMethodInstaller%2FSimple.pm;h=da6e2c095337038ddc6f1001fc63d7fa6aca0e1f;hb=7bf7590532f15b0400ad948818b090d2e9e18d32;hp=a5f0c379bae2e1b87efcaf3ababdabf242a4f77a;hpb=9de3c0575dae5881780a79b80867ae983edb7cc9;p=p5sagit%2FDevel-Declare.git diff --git a/lib/Devel/Declare/MethodInstaller/Simple.pm b/lib/Devel/Declare/MethodInstaller/Simple.pm index a5f0c37..da6e2c0 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.003005'; +our $VERSION = '0.006009'; 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 {