I am developing an application that has to replace an existing mess of spaghetti-code piece by piece. To achieve this I have a dispatcher that runs required HTTP resources when a URI has been matched and otherwise uses the legacy HTTP resource class.
So, this legacy HTTP resource has to require the entry point file of the old system, and I’m trying to figure out how to test this process. The way I see it now is I would like to replace the original require function with a mock subroutine and check that it has been called with an appropriate file name.
Is this possible, and if not, maybe there is a better way to do it?
A better way to override
requireglobally may be to install a hook into@INC. This little-known functionality is described at the end of therequiredocumentation.Here’s a simple example that intercepts any request for a module whose name begins with HTTP:
Note that this also mocks
use, since it’s based onrequire.