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

Hi,

I'm wondering a bit about the worth of adding some older scripts of mine to the cpan, as cpan is pretty much geared to finer-grained function or oo-level reuse instead of coarser pipe/cli level reuse.

At the moment, the victim in question is still a proper standalone script, being wrapped into a tarball setup via module-starter. So if I upload the script to PAUSE, it gets onto cpan.org/scripts, and the tarball is visible with search.cpan.org. Even smoke-testing is active, but rt refuses to see non-official modules.

You can find the victim of this question (aka waitcond) here: http://cpan.org/authors/id/J/JA/JAKOBI/scripts/cliprocesses/

While I have one hard condition that the script must be usable standalone and remain directly usable at the pipe level, turning it into a dual-nature function-library-style module that can still be invoked like a script isn't too difficult. A bit tasteless maybe: That's not a proper refactoring (rather a minor cleanup at best) plus I don't really see many programmatic advantages of 'use' over 'system' for a fairly 'slow' command. OTOH, people knowing cpan could use standard cpan features like CPAN.pm to get/update the script/module, report bugs with rt, etc.

So the first question is: is this worth the effort? Or should perl scripts really leave CPAN and go to say freshmeat as their proper place?

A second harder question: If CPAN is still also somewhat suitable for scripts, what is the preferred name / module hierarchy? Even stuff like App:: looks more like support-for-applications than applications or scripts proper; in addition, it lacks hierarchical structure, thus placing things in App:: feels too much like littering... .

The only example somewhat comparable to my question seems to be App::Ack.

thanx for joining this puzzle with me,
Peter

Replies are listed 'Best First'.
Re: cpan and (dual-nature) scripts?
by ELISHEVA (Prior) on Sep 29, 2009 at 08:17 UTC
    While I have one hard condition that the script must be usable standalone and remain directly usable at the pipe level, turning it into a dual-nature function-library-style module that can still be invoked like a script isn't too difficult. A bit tasteless maybe: That's not a proper refactoring (rather a minor cleanup at best) plus I don't really see many programmatic advantages of 'use' over 'system' for a fairly 'slow' command.

    CPAN modules are normally used as building blocks. The advantage of giving your script a functional interface is that it makes it easier to use as a building block. You currently use your script as part of a pipeline, but your callers may have other ideas about how they want to attach input and output streams to your program. By providing a routine that accepts an input and output file handle, you give your future users design options other than a system pipeline. For example, they may wish to have code that runs between the point where the input file handle is created and your routine is called. They may have a single output file handle and a family of input file handles they want to feed to your routine or vice versa.

    You also make your program more portable. The system command is not available on all platforms and even if it is implemented, it may not always be possible to request a sequence of commands each piping their output into the next. See perlport for details.

    Best, beth

      thanx for the heads-up for q1/modulification, Beth :)

      For the tcgrep-fork I started to hack on ages ago (who doesn't have a perl grep of his/her own with some special tricks :) ), I indeed recently turned it into a dual nature module. Which I yet have to use as a module... . So I might also find some time to do that for all 5 candidate scripts regardless of cpan or no cpan.

      Portability other than Unix-Unix: not quite my cup of tea, with the possible exception of cygwin :>.

      As for waitcond, its usable output information is basically just the return code and the fact that it exited: so pipeline in this case includes shell command sequences as well. (cmd1; waitcond...; cmd2)|cmd3. Consider a  ssh HOST make in one shell window, and using waitcond in a different shell for e.g. the tty of the ssh/make command to be idle for more than a few minutes: waitcond not recent tty /dev/pts/13; mpg123 trumpets-of-jericho; echo check for make success or early failure.... (waitcond is the worst of the bunch with its pure process/shell conception)

      So let me ask a question 2b:

      I've absolutely no naming idea: where in the main module hierarchies e.g. waitcond might fit. Other than maybe not signaling its dual-module/script-nature and just selecting a module hierarchy that at least somewhat matches a not entirely-impossible use case.

      Sys::, Proc::, App:: ??? All of which fit (badly/way too generic).

      Toplevel (but isn't that even worse)??

      ???
Re: cpan and (dual-nature) scripts?
by dolmen (Beadle) on Oct 01, 2009 at 14:57 UTC

    Packaging for CPAN is the best thing to do. Congratulations for your first distro!

    Your release is quite clean.

    Just change Build.PL to add requires for the modules used in tests: Test::More, File::Spec::Functions.

    Also, your test t/waitcond.t seems quite light: you are just checking the script syntax with 'perl -c'. You may use instead a CPAN module: Test::Script. This will be more portable.

    Any ideas for really testing the script execution?

        Thanx for giving it a review, dolmen. Any takers for my naming/category issue :)?

        I've updated my local Build.PL's build_requires (=>0,), thanx for the tip.

        (and yes, the amount of test green also surprised me)

        As for the tests, I might go from really very light to just fairly light, but a realistic portable testset to be run from CPAN.pm just doesn't seem quite realistic to me:

        Portability for some of waitconds functionality like iostat (diskidle) is one problem, writing a portable test for that is another, quite worse one. Plus the 30 second delay required to get something at least somewhat sane out of iostat...

        Btw1, is there some Perl standard distribution location for such extra stuff, to get it installed in the filesystem, but out of the way? Other than say just occupying /usr/local/share/doc/waitcond_cpan_distribution? (and anything /usr requires being root or a sudo prefix in the CPAN.pm config, something I'm also not that happy about)

        q2, is there a way to add cygwin (but not pure windows) as an os for the cpan testers?

        q3, my current understanding is that the tests may be automated, but the report may also be manually augmented(?) to contain some additional information and comments. Are such augmented/more valuable reports marked or filterable in some way? Or do I have to hope for the tester to fail the test, or add an email so I at least won't miss his comments/reviews?