Mailing List Archive

Re: h2xs 1.12
>From: Andreas Koenig <k@anna.mind.de>

>Dean Roehrich <roehrich@cray.com> writes:
>
> > We need to get MM to set the PM's version number, folks. Right now MM
> > doesn't help us at all unless the extension uses two or more XS files, and
> > that's a rare occasion.
>
>I cannot see any justification to change any file while running
>Makefile.PL. The reasonable way IMO is to go the other
>direction. Makefile.PL *parses* a pm file and determines the version
>number. This is currently up to the authors, and I admit, we could
>make it easier for them.

Sounds good to me, as VERSION_DRIVER or VERSION_FROM.

Okay, if this happens, we can replace the MM VERSION attribute with
'VERSION_DRIVER' => 'Foo.pm',
right? Then, in this case, the version is always set in Foo.pm and MM makes
sure that XS_VERSION matches it?

Should h2xs use this in its Makefile.PL template?

>
> while(<PM>) {
> if(/^\s*\$VERSION\s*=/) {
> $version = eval $_;
> last;
> }
> }

I may have a 'local' or 'my' on the front. I may have it fully-qualified.

>From: Tim Bunce <Tim.Bunce@ig.co.uk>
>I'd use a local($VERSION) and not use the return value from the eval.
>I'd also loosen the /^\s* since some people may do ($VERSION = ...) =~ ...;

That, too.

The code below handles all of the cases mentioned here.

Dean

-------
$module = 'FOO';
local $VERSION;
while(<DATA>){
chop;
if( /VERSION[^=]*=/ ){
s/^\s*(?:my|local)//;
print "eval($_)\n";
eval $_;
print "version($VERSION)\n";
}
}
__END__
$VERSION = '1.00';
my $VERSION = '1.01';
my( $VERSION ) = '1.011';
my( $VERSION ) = '$Revision: 1.12 $' =~ /\$Revision:\s+([^\s]+)/;
local $VERSION = '1.02';
$FOO::VERSION = '1.10';
my $FOO::VERSION = '1.20';
local $FOO::VERSION = '1.30';
Re: h2xs 1.12 [ In reply to ]
>>>>> " " == Dean Roehrich <roehrich@cray.com> writes:

> Sounds good to me, as VERSION_DRIVER or VERSION_FROM.

VERSION_FROM then, less to type and selfexplaining.

> Okay, if this happens, we can replace the MM VERSION attribute with
> 'VERSION_DRIVER' => 'Foo.pm',
> right? Then, in this case, the version is always set in Foo.pm and MM makes
> sure that XS_VERSION matches it?

VERSION and VERSION_FROM are mutually exclusive. I will let have
VERSION_FROM precedence and ignore VERSION if it is set (with a
warning). XS_VERSION defaults to VERSION and will be defined on the
command line of the compiler call with C<-DXS_VERSION=...>, I don't
intend to do further checking on it. (Except I'm missing something
now)

Is there any reason to have a -DVERSION=... for the compiler call
anymore? I mean except for backwards compatibility?


> Should h2xs use this in its Makefile.PL template?

You are quick :-) Yes.

[...]

> I may have a 'local' or 'my' on the front. I may have it fully-qualified.

>> From: Tim Bunce <Tim.Bunce@ig.co.uk>
>> I'd use a local($VERSION) and not use the return value from the eval.
>> I'd also loosen the /^\s* since some people may do ($VERSION = ...) =~ ...;

> That, too.

> The code below handles all of the cases mentioned here.

Thank you for the code, that was really quick.

> Dean

andreas
Re: h2xs 1.12 [ In reply to ]
>>>>> "dean" == Dean Roehrich <roehrich@cray.com> writes:

>> From: Andreas Koenig <k@anna.mind.de>
>> Dean Roehrich <roehrich@cray.com> writes:
>>
>> > We need to get MM to set the PM's version number, folks. Right now MM
>> > doesn't help us at all unless the extension uses two or more XS files, and
>> > that's a rare occasion.
>>
>> I cannot see any justification to change any file while running
>> Makefile.PL. The reasonable way IMO is to go the other
>> direction. Makefile.PL *parses* a pm file and determines the version
>> number. This is currently up to the authors, and I admit, we could
>> make it easier for them.

[...]

dean> I may have a 'local' or 'my' on the front. I may have it fully-qualified.

Objection. local() and my() make a bad interface for a variable that
_has_ to be visible. I don't think, a private variable should be
allowed for $VERSION. That's why we have agreed upon the name of the
variable. Because we want to have it accessible from outside. Maybe I
want to use your module, but write some code that is only needed if I
get at a $VERSION<1.23 of your module.

>> From: Tim Bunce <Tim.Bunce@ig.co.uk>
>> I'd use a local($VERSION) and not use the return value from the eval.
>> I'd also loosen the /^\s* since some people may do ($VERSION = ...) =~ ...;

dean> That, too.

That's done.

dean> The code below handles all of the cases mentioned here.

Didn't really. Didn't catch $@ for my($FOO::VERSION) which is a syntax
error, and didn't print the intended result for $FOO::VERSION and
local($FOO::VERSION).

dean> $module = 'FOO';
dean> local $VERSION;
dean> while(<DATA>){
dean> chop;
dean> if( /VERSION[^=]*=/ ){
dean> s/^\s*(?:my|local)//;
dean> print "eval($_)\n";
dean> eval $_;
dean> print "version($VERSION)\n";
dean> }
dean> }
dean> __END__
dean> $VERSION = '1.00';
dean> my $VERSION = '1.01';
dean> my( $VERSION ) = '1.011';
dean> my( $VERSION ) = '$Revision: 1.12 $' =~ /\$Revision:\s+([^\s]+)/;
dean> local $VERSION = '1.02';
dean> $FOO::VERSION = '1.10';
dean> my $FOO::VERSION = '1.20';
dean> local $FOO::VERSION = '1.30';

My current version inhibits both my and local with something close to
the following:

#!/usr/bin/perl
while(<DATA>){
chop;
next unless /\$([\w:]*\bVERSION)\b.*=/;
local $ExtUtils::MakeMaker::module_version = $1;
package main;
my($eval) = "$_;";
print "eval($eval)\n";
eval $eval;
die $@ if $@;
print "version($$ExtUtils::MakeMaker::module_version)\n";
}

__END__
$VERSION = '1.00'; #ok
($VERSION) = '$Revision: 1.12 $' =~ /\$Revision:\s+([^\s]+)/;#ok
$FOO::VERSION = '1.10'; #ok
my $VERSION = '1.01'; #prints 1.12
local $VERSION = '1.02'; #prints 1.12
local $FOO::VERSION = '1.30'; #prints 1.10



I'm ready to release this, but maybe you want to say something about it...

andreas
Re: h2xs 1.12 [ In reply to ]
> From: Andreas Koenig <k@anna.mind.de>
>
> >>>>> "dean" == Dean Roehrich <roehrich@cray.com> writes:
>
> >> From: Andreas Koenig <k@anna.mind.de>
> >> Dean Roehrich <roehrich@cray.com> writes:
> >>
> >> > We need to get MM to set the PM's version number, folks. Right now MM
> >> > doesn't help us at all unless the extension uses two or more XS files, and
> >> > that's a rare occasion.
> >>
> >> I cannot see any justification to change any file while running
> >> Makefile.PL. The reasonable way IMO is to go the other
> >> direction. Makefile.PL *parses* a pm file and determines the version
> >> number. This is currently up to the authors, and I admit, we could
> >> make it easier for them.
>
> [...]
>
> dean> I may have a 'local' or 'my' on the front. I may have it fully-qualified.
>
> Objection. local() and my() make a bad interface for a variable that
> _has_ to be visible.

I _think_ local() at file scope is harmless (and useless).

> I don't think, a private variable should be
> allowed for $VERSION.

It _can't_ be a 'my' since the XS code need to be able to look it up by name.
Using a 'my' should generate a warning from MakeMaker.

Tim.