tirwhan has asked for the wisdom of the Perl Monks concerning the following question:
Hi monkses,
I have a feeling there probably is no clean solution for my problem but knowing the brilliant people here I thought I'd ask. My application uses a CPAN module which itself calls out to another CPAN module, and I need that method call to contain an additional parameter. Code makes this easier to explain:
MyCode.pmUsefulMod.pm (from CPAN)package MyCode; use UsefulMod qw(uf_method); uf_method();
package UsefulMod; sub uf_method { # lots of code require Backend; # Also from CPAN my $r = Backend->new() # This is where I need a parameter passed $r->do_useful_stuff(); # lots of code }
So what I need is for Backend->new() to be Backend->new("filename") so that the module uses the file as additional datasource. The obvious (and horrible) way to fix this is is to change the local UsefulMod.pm file to contain the parameter, but this will break whenever the module is updated by an unknowing admin, so I don't want to do that.
My usual way to handle this would be to override UsefulMod->uf_method() or even Backend->new() in my own module to change the behaviour in the desired way, but both of them contain gobs of other code, and maintaining a changed version of this code in my own module seems to me almost just as much a recipe for disaster. Does anyone know a clever and responsible way I can do this?
Additional info for the interested: This isn't just an academic exercise, I'm using Data::FormValidator::Constraints::Upload which employs File::MMagic to recognize uploaded filetypes(I used fantasy names above because I figured my issue would be easier to explain that way). File::MMagic only contains a relatively short list of "magic" declarations, and does not recognize a file type I need it to without being pointed at the magic.mime file installed on the system.
This being open source I can of course send a patch to the maintainer of Data::FormValidator::Constraints::Upload, adding the "magic" file location as a parameter passed into the DFCU constructor. But I wonder whether this would be a good idea, seeing as it exposes the internal workings of DFCU to the module user and may lead to incompatible API changes if DFCU ever wants to switch away from File::MMagic. Any comments on that aspect would also be appreciated.
Update:Corion's solution works perfectly, thanks a lot!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Changing a method call in a CPAN module
by Corion (Patriarch) on May 10, 2007 at 12:04 UTC | |
by derby (Abbot) on May 10, 2007 at 12:23 UTC | |
by Corion (Patriarch) on May 10, 2007 at 12:31 UTC |