http://www.perlmonks.org?node_id=1007279


in reply to change perl function in runtime

Sounds like you need to: and then mock function y. If all you want to do is generate a die() when you call it, then simply manipulating the symbol table as others have suggested would probably be sufficient, or you might want to use Test::MockObject. If you want to be a bit more rigourous, so that as well as testing that your code behaves correctly when 'y' dies but also test that you call y correctly, I recommend Class::Mockable and Class::Mock::Generic::InterfaceTester.