Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Editing files in a module

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

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

Brethern,

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?

throop

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 }

    -Paul

      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 yourApp.pl

    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.



    --chargrill
    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
    Brethern,

    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 Grapher.pm in the Module::Dependency CPAN module. I have it sitting in /home/throop/perl/Module-Dependency-1.86/lib/Module/Dependency/Grapher.pm 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/Grapher.pm, 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/Grapher.pm

    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.

    throop

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found