my $LOG_ERROR; my $_log_error_sub_cache; sub setup { my $class = shift; $class->SUPER::setup_test; $_log_error_sub_cache = *RTK::Digitrak::LogRun::_log_error{CODE}; no warnings 'redefine'; *Foo::Bar_log_error = sub($) { $LOG_ERROR = shift }; } sub teardown { my $class = shift; $class->SUPER::teardown_test; no warnings 'redefine'; *Foo::Bar:_log_error = $_log_error_sub_cache; }