|more useful options|
hijacking a module constructorby hackmare (Pilgrim)
|on Nov 03, 2003 at 16:32 UTC||Need Help??|
hackmare has asked for the wisdom of the Perl Monks concerning the following question:
is it possible to re-map a method call to redirect it to another module? I am trying to replace all calls to GD.pm with SVG::GD.pm down the dependency tree by modifying the mail program and not modifying any program that may inherit GD.pm.
The latter provides all the call support for GD.pm but generates SVG (and) implements the GD library.
All this is great, but now I want to use GD::Graph::Bar (for example), and I need to make the change at the main program level only (not within the GD::Graph::Bar namespace). I need the fact that I am using SVG::GD to superscede all calls to the GD module.
GD::Graph::Bar has calls to GD buried deep inside them, and I want to hijack all the GD constructor calls to use the SVG::GD constructor instead. Ingrate that I am, I'm hoping that I can do this from the main namespace so a user can select to use SVG::GD rathern than be forced to use the GD.
(In short, for example, I want to apply s/GD::Image/SVG::GD::Image/g in the source code)
Can this be done? I seem to remember hearing of this being done at one of the yapc's, but don't have the slightest idea where to look. I'm starting to feel way above my head here and would appreciate a nudge in the right direction or towards the right reference.