Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Editing files in a module

by throop (Chaplain)
on Dec 18, 2006 at 16:31 UTC ( #590478=perlquestion: print w/replies, xml ) Need Help??

throop has asked for the wisdom of the Perl Monks concerning the following question:


I'm building an application, call it App. It uses a module, call it Module, which I got at CPAN. I installed Module, did a make. It's got some bugs and I want to add some functionality to it. So I'm editing files in Module, and testing with a test script that calls App, which calls Module in turn.

Every time I make a change to Module, I'm performing another make. This adds another step and another 30 sec or so to the the debug/edit/test cycle. Seems like I should be able to skip the make step while I'm testing; maybe by having something that quickly changes my PATH variable so that App executes the edited code rather than the binaries. But that seems a little kludgey and error prone. What do other do?


Replies are listed 'Best First'.
Re: Editing files in a module
by jettero (Monsignor) on Dec 18, 2006 at 16:41 UTC

    Chargrill is definitely correct. I do that very thing from time to time while developing.

    But, please also consider that editing the module directly may be the wrong approach — unless you intend to release patches to the module maintainer. Otherwise, the next time you install a new version of Module, you'll have to make all your changes all over again.

    package BetterApproach; use strict; use warings; use Module; use base qw(Module); sub extended_function { my $self = shift; if( $something ) { # new stuff return $new_stuff } $self->SUPER::extended_function(@_); # old stuff }


      and if you can't submit your improvements to the original module's author or if your modifications dont fit with the intent of the original, rewrite the module in question under a subsequent namespace (making sure to credit the original module and author, especially if you're largely including any of their code).

      ie: if the original module was App::Functionality, name your modified module App::Functionality::Extra

      The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
      - Terry Pratchett

Re: Editing files in a module
by chargrill (Parson) on Dec 18, 2006 at 16:36 UTC

    You could just use the -I flag to perl, i.e.:

    $ perl -I/path/to/edited/Module

    Though I don't recall off the top of my head if that puts the path/to/edited/Module at the top of @INC or not ... but surely a trip to perlrun could clear that up for you.

    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: Editing files in a module
by throop (Chaplain) on Dec 18, 2006 at 22:01 UTC

    Thanks for the helpful replies. It took me a little while to interpret some of it correctly, so I herein post my trouble for anybody else who is trying to do the same.

    The -I suggestion was very helpful, but I was not having any joy trying to give it two directories to add to @INC. The Camel doc told me that it was preferable to use lib in the script instead of -I in the call to Perl. Did that. I am editing in the Module::Dependency CPAN module. I have it sitting in /home/throop/perl/Module-Dependency-1.86/lib/Module/Dependency/ Naively, I entered the code:

    use lib qw(/home/throop/perl/Module-Dependency-1.86/lib/Module/Depende +ncy);
    which didn't work. The Module/Dependency in the string was the culprit. Perl went looking for /home/throop/perl/Module-Dependency-1.86/lib/Module/Dependency/Module/Dependency/, didn't find it, quit. What worked was
    use lib qw(/home/throop/perl/Module-Dependency-1.86/lib);
    letting Perl transmogrify Module::Dependency::Grapher into Module/Dependency/

    As for the wisdom of modifying CPAN module code — point taken. I wrote the maintainer with some queries and he noted that the particular section of the code that I need hasn't received much loving for a long time; asked me to update it. I may do that; I'm having discussions with my employer. I know about forgiveness and permission but I'm wish to be careful and scrupulous.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-10-30 02:38 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (277 votes). Check out past polls.