sub wrap_sub { my ($class, $function) = @_; no strict 'refs'; no warnings 'redefine'; my $referent = \&{"$class\::$function"}; my $wrap_sub = sub { warn 'before'; $referent->( @_ ); warn 'after'; }; warn "wrap_sub wrapping: $class\::$function"; no warnings 'redefine'; *{"$class\::$function"} = $wrap_sub; return; } #### sub foo { warn 'fooooo'; } __PACKAGE_->wrap_sub("foo");