Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

BooK (2612)

  {book} {at} {}
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation []. Pink []. HTTP::Proxy []. YEF []. Fishnet []. Kapow []. Cog's [] bitch []. Invitation []. White [] Camel []. Nuff' said.

Journal of BooK (2612)

Friday December 10, 2004
04:38 AM


[ #22248 ]

I am subscribed to both TPR and TPJ and I do not regret it*. After all, I can read brian d foy's articles in both publications... ;-)

And in November's TPJ, I could read his article about Modulinos. This is such a great idea!

Now that I am compulsive about tests, I'm very disappointed with how I can test scripts. These tests are a pain to write: it's difficult to cover all the tests, I have to create loads of data and configuration files to check for each case, I do not get test coverage, etc. Test::Cmd is a great tool (except that I can't have two instances of a Test::Cmd at the same time) but, as bdfoy notes, when testing scripts, you only test the whole process. Does that input produce the expected output? How many files appeared and weren't removed? And so on.

Most of the time, a script is a set of individual actions combined according to the command-line options. Sure, but I don't want to write a whole module and install it in @INC, just to encapsulate those individual actions.

Well, now I can. I just write the module inside the script file, add the magic one-liner** given by brian, and write tests scripts!

The only drawback in my opinion is that, if you want to use the "module", you'll have to name your script If it's only for scripts, I guess you can simply require "foo" in the test suite. And Devel::Cover works as expected!

I think I'll use^Wrequire^Wuse this technique for my future production scripts.

(*) Except for the fact that TPJ is online only... Did you also notice that, contrary to almost every magazine, a particular month's issue is available at the end of the month? I suppose they were late at some point, and never catched up.

(**) You noticed I did not write the one-liner here. It's on purpose. Either 1) brian will write it somewhere for all to see, or 2) you'll subscribe to TPJ. Or both.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I first talked about the idea of modulinos on Perlmonks: How a script becomes a module []. It's a much longer version of what appears in TPJ, although the TPJ version is much more polished and developed.

    As for the drawback about naming the script, I thought I had talked about that in the article (although I haven't read what they published. I can't read my own stuff once someone else publishes it). The trick is to create the module and install it in the usual place, then create a symlink (or link) to it fo