Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Mucking around with module imports

by Viko (Acolyte)
on Jul 20, 2010 at 13:06 UTC ( #850420=perlquestion: print w/ replies, xml ) Need Help??
Viko has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks,

I want to overload CGI.pm with some minor tweaks of mine. It has to have the same name (using use 'lib' or PERL5LIB to access mine first), due to the number of files I'd have to change in order to replace the original with mine. The problem is that my module has to call the original CGI.pm after it's done.

Any ideas? I've tried removing the lib path with a BEGIN block but that breaks other module imports that rely on my base lib path.

Here's some pseudo code:

use lib '/path/to/my/root/lib'; use CGI; #this one is mine, found under /path/to/my/root/lib/CGI.pm # need to find a way to 'use', or 'use base' the original CGI.pm here #... some code here to set $query_string... return CGI->new($query_string); # this Lincoln Stein's CGI.pm

Thanks in advance,
Vinny.

Comment on Mucking around with module imports
Select or Download Code
Re: Mucking around with module imports
by Anonymous Monk on Jul 20, 2010 at 13:07 UTC
    Subclass

      ??

      Subclass as in 'use base'? How will 'use base qw{CGI}' know that I want Lincoln Stein's CGI and not the first one it finds (mine, in my lib base, which is the first element of @INC) ?

        Um, don't call your module CGI, call it VikoCGI or some such, the name is taken, don't ya know :)
Re: Mucking around with module imports
by moritz (Cardinal) on Jul 20, 2010 at 13:16 UTC
    The simple answer is "don't". It will confused the heck out of everybody reading the code.

    That said, if you understand it's a stupid idea, and you're convinced that there's no betters solution (if you told us what your deeper problem is, maybe we could find one for you?), there are still two approaches:

    1) edit the existing CGI.pm and add your changes. Optionally with copying to another location first.

    2) you can try to remove CGI.pm from %INC, remove the paths where the current module was found from @INC, and then use CGI; and have fun.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Mucking around with module imports
by chromatic (Archbishop) on Jul 20, 2010 at 16:06 UTC
    It has to have the same name ... due to the number of files I'd have to change in order to replace the original with mine.

    Write a little perl -pi -e 's/\bCGI\b/VinnyCGI/g' program, run your tests, then check the diff in your VCS. The price you pay for this renaming is much less than the maintenance costs of this hack.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://850420]
Approved by Perlbotics
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-28 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls