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

I have something I believe to be CPAN worthy. I've started looking at making my code CPAN-friendly. I was given a link at the perl5 porters mailing list that has some good info, I believe. One thing confuses me though:

A module's code has to be warning and strict-clean, since you can't
guarantee the conditions that it'll be used under. Besides, you wouldn't
want to distribute code that wasn't warning or strict-clean anyway,
right?

What exactly does this mean? Does this mean 'use strict' and '-w' shouldn't be used, or does this mean to use them?

Could merlyn or some of the other module writing monks give me some guidance?

Thanks,

JJ

Replies are listed 'Best First'.
Re: Creating modules for use on CPAN
by lhoward (Vicar) on Jun 12, 2000 at 22:30 UTC
    It means that your code should run without any errors or warnings generated if "use strict" and "use warnings" are in effect. Ideally you should h2xs to generate your module template. h2xs automatically puts "use strict" and "use warnings" in your module.
    h2xs -A -X -n File::CMP
    (merlyn will surely recognize where I stole that example from...)
    My understanding is that "use warnings" is the prefered usage since its introduction and that -w is depricated (though still well supported). For this reason I've gotten in the habbit of saying "use warnings" instead of -w.
      Not 'use warnings', but -w. The warnings pragma came into the Perl distrobution I believe in 5.005_63, so not everyone will have it, but everyone has -w. On an aside, of you are using a pragma, or something which came out in a version of Perl (for example, say you use our(), which came in 5.6), you may want put at the top of your script:

      require 5.6;

      Cheers,
      KM

Re: Creating modules for use on CPAN
by KM (Priest) on Jun 12, 2000 at 22:30 UTC
    It means it has to run cleanly with -w and use strict. Which, you would want to do anyways, of course :)

    Cheers,
    KM

Re: Creating modules for use on CPAN
by Anonymous Monk on Jun 13, 2000 at 05:31 UTC
    It seems to me that when testing code one should use strict, but when distributing it one should not. It is possible that a coding error in perl (the interpreter, not the language Perl) on certain platforms could cause a program that has use strict in it to break.