tags:

views:

114

answers:

5

Do I have to run make and make install each time I change a .pm file for Perl? I'm doing a ton of testing and this is becoming cumbersome.

A: 

No, there is no need to do that.

David Dorward
Downvote because answer is snarky: while superficially correct, ultimately unhelpful.
daxim
+3  A: 

It depends on module setup, but under the standard MakeMaker I use, "make test" runs a "make" if any files have been modified, so when doing intra-module development "make test" is the only command you need until you've finished.

Todd Gardner
I don't even see how this is close to a 'good' answer, all he is claiming is that his make-system has logic to only rebuild if needed -- like every make system, and that it is run under `test` too. You still have to run `make test` and it still has to run `make`, furthermore you never said anything about testing anywhere in the question, nor did you mention using XS or anything that would require compilation.
Evan Carroll
@Evan, you may not see how this is a good answer, but it is the right answer. It works reliably in all situations, whereas yours does not.
brian d foy
It doesn't answer the question: the question doesn't mention testing. The question mentions installing. The answer mentions testing and not installing. The answer also mentions MakeMaker which is not present in the question.
Evan Carroll
I think you missed the word "test" in the question. Read it again. It'a always been there, as has "make".
brian d foy
No, I think you added the word "test", per the history of the question.
Evan Carroll
A: 

Presumably you're editing a lib module in a non-lib location, rather than clobbering a global library for each modification - do the sensible thing and change the library path perl uses with PERL5LIB, which will append internally to @INC (the use search path):

PERL5LIB=/home/user/code/perl/project/lib perl myapp.pl

If your program isn't pure-perl and requires a make system, there is no way to do this short of rebuilding, but pure-perl (PP) doesn't really require make under normal circumstances. If you do it this way, running perl under a normal environment will yield the predictable and tested results, running it with your PERL5LIB will allow you to test the program.

Evan Carroll
Don't do it this way. Don't get into the habit of testing what is in lib. Use the build system to put things into blib and test from there so you don't get into this bad habit and wonder why it doesn't work in some cases. It's so much easier to do it the right way that works in every case.
brian d foy
Is it the right way because it is your way, or is the right way for some substantial other reason? I don't think you read my posts, I think you stalk me and drop in with silly reasons to downvote. My context of test, was a real world application not a unit test, as unit tests aren't mentioned in the question. But, I would agree, if it was a unit test, you're better off not messing with PERL5LIB, and using prove. (which I had said above when it was assumed the question pertained to a unit test).
Evan Carroll
It's not my way. I didn't make it up. It is better on its merits, though. Don't flatter yourself about stalking and victim fantasies.
brian d foy
Geez Evan, lay off the guy. I've been watching you defensively comment-snipe brian all over ST.
Schwern
+1  A: 

Evan Carroll got it basically right. To expand on his answer: use the testing tools that come with Perl to tighten the workflow.

Let's say you are in your project directory and you hack on the files in its lib/ subdirectory. Execute prove -l to run all tests. That's easier than messing with absolute paths in the PERL5LIB environment variable.

daxim
I assumed the purpose of `make install` was to run applications -- though I can now see it being used to run tests. I use `prove` all day long, sometimes I take for granted other people don't know about it.
Evan Carroll
+5  A: 

You don't have to install the module to test it.

If I'm testing inside my distribution directory, I just use the test target:

 % make test

Or, if I'm using Module::Build:

 % ./Build test

Since make is a dependency management tool, it also takes care of any other steps it needs to perform so it can run the test target. You don't need to run each target separately. Module::Build does the same thing.

If I want to test a single file, I combine the make command with a call to perl that also uses the blib module to set the right @INC:

 % make; perl -Mblib t/single_test.t

Some people like using prove for the same thing. No matter which method I use, I'm probably using the arrow keys to move back to a previous command line to re-run it. I do very little typing in any of this.

brian d foy