On Feb 15, 2012, at 6:43 AM, Peter Karman wrote:

> Status: Decreasing version number
>          =================================
> 
>     module: Lucy::Analysis::Analyzer
>          version: undef
>          in file: lib/Lucy/Analysis/Analyzer.pm
>          status: Not indexed because lib/Lucy/Analysis/Analyzer.pm in
>             D/DW/DWHEELER/Lucy-0.2.2.tar.gz has a higher version number
>             (0)
> 
>     module: Lucy::Anal

You built the distribution with Module::Build version 0.3603, which sets 
versions in the "provides" section to `undef` if there is no version.

I built 0.2.2 with Module::Build version 0.38, which sets missing versions in 
the "provides" section to 0. From the CPAN indexer’s point of view, 0 != undef.

I argue, however, that *all* Lucy modules should have explicit versions. Why? 
Let’s say that I have a module that depends on Lucy::Analysis::Analyzer. So I 
declare in my Build.PL:

    requires => {
        'Lucy::Analysis::Analyzer' => 0,
    }

So far so good, right? But let’s say that I later realize that I need a new 
feature in 0.3.0. Si I change it to:

        'Lucy::Analysis::Analyzer' => '0.3.0',

If someone tries to build, it will fail, because there is no such version. In 
fact, CPAN cannot tell the difference between the Lucy::Analysis::Analyzer in 
0.3.0 and the Lucy::Analysis::Analyzer in 0.2.2 or any other release. Because 
we did not give it a version number. Since the best practice is for developers 
to declare requirements on modules they actually `use`, and one may not 
actually `use Lucy;`, folks may not then require a specific version of Lucy, 
but rather of a module that Lucy packages.

So, IME, it is best for every Perl module in a distribution to have its own 
version. This version does not have to change with each release if its contents 
have not changed, but I tend to find that a bit complicated (since other 
modules it depends on may have changed, and those changes might have 
side-effects on my module). So better, IME, is to have the same version in 
every single module in a distribution. You can see this at work in all of my 
distributions, e.g.,

  http://search.cpan.org/dist/DBIx-Connector/

There are two ways to do this. One is to have this line in every .pm file:

    our $VERSION = '0.003001';

Then, before a release (or just after a release, depending on your 
preferences), you would change it every file. I do that with something like:

    ack -laiQ 0.003000 | xargs perl -i -pe "s{\QVERSION = '0.003001'}{VERSION = 
'0.003001}g"

Some might find it a bit annoying, but it’s probably the safest way to manage 
Perl module versions. The second way to do it is lazier: Just put this line in 
every Perl module in a distribution:

    require Lucy; our $VERSION = eval $Lucy::VERSION;

And yes, it has to be on one line so that Module::Build will parse out the one 
line and eval it. I think this would be safe, though I don’t know if you want 
to load Lucy.pm in every file.

Anyway, best practice is to have an explicit version in every module and to 
make sure it’s properly set for every release.

The upshot for this particular release is that only Lucy.pm is indexed. So if 
you `cpan Lucy`, it will install, but if you `cpan Lucy::Analysis::Analyzer`, 
you’ll get an error:

    Warning: Cannot install Lucy::Analysis::Analyzer, don't know what it is.
    Try the command

        i /Lucy::Analysis::Analyzer/

Best,

David



Reply via email to