On Fri Mar 25 08:58:17 2011, mmaslano@redhat.com wrote:
Show quoted text> If I try normalize alpha version beginning with "v", it creates very odd
> version. Not sure if this is a bug or intentional behaviour.
It is the unfortunate nature of Perl's own parser/tokenizer.
Show quoted text> perl -Mversion -e 'print version->parse(1.02_23)->normal'
> v1.22.300
The underscore is completely ignored by the parser because this is a
bare number (which can contain underscores every other character). So
what version->parse receives as a parameter is:
$ perl -MDevel::Peek -e 'my $vs = 1.02_03; Dump($vs)'
SV = NV(0xa3f4370) at 0xa3afee0
REFCNT = 1
FLAGS = (PADMY,NOK,pNOK)
NV = 1.0203
which is then split on three decimal places by parse() and thus becomes
v1.22.300.
Show quoted text> perl -Mversion -e 'print version->parse(v1.02_23)->normal'
> v1.2_23
This is interpreted by the Perl parser as a v-string (which is a lossy
translation):
$ perl -MDevel::Peek -e 'my $vs = v1.02_03; Dump($vs)'
SV = PVMG(0xbe6da30) at 0xbe1aee0
REFCNT = 1
FLAGS = (PADMY,RMG,POK,pPOK,UTF8)
IV = 0
NV = 0
PV = 0xbe310d0 "\1\303\213"\0 [UTF8 "\x{1}\x{cb}"]
CUR = 3
LEN = 8
MAGIC = 0xbe3f370
MG_VIRTUAL = 0
MG_TYPE = PERL_MAGIC_vstring(V)
MG_LEN = 8
MG_PTR = 0xbe2d010 "v1.02_03"
However, the version.pm code takes the contents of the _original_ string
(as stored in the MG_PTR structure above), and reparses it. This means
the underscore is preserved and can be interpreted as an Alpha version.
If you want to force an Alpha version, and preserve what you mean in the
face of the Perl parser, you must quote the values you pass to version.pm.
On the other hand, if you want to always assume the version is a
dotted-decimal version (with or without an alpha), then you should be
using version->declare instead of version->parse. Thus:
$ perl -Mversion -MData::Dumper -e 'my $vs =
version->declare("1.02_03"); print Data::Dumper->Dumper($vs)'
$VAR1 = 'Data::Dumper';
$VAR2 = bless( {
'qv' => 1,
'alpha' => 1,
'original' => 'v1.02_03',
'version' => [
1,
2,
3
]
}, 'version' );
and
$ perl -Mversion -MData::Dumper -e 'my $vs =
version->declare("v1.02_03"); print Data::Dumper->Dumper($vs)'
$VAR1 = 'Data::Dumper';
$VAR2 = bless( {
'qv' => 1,
'alpha' => 1,
'original' => 'v1.02_03',
'version' => [
1,
2,
3
]
}, 'version' );
vs
$ perl -Mversion -MData::Dumper -e 'my $vs = version->parse("1.02_03");
print Data::Dumper->Dumper($vs)'
$VAR1 = 'Data::Dumper';
$VAR2 = bless( {
'width' => 2,
'alpha' => 1,
'original' => '1.02_03',
'version' => [
1,
20,
300
]
}, 'version' );
and
$ perl -Mversion -MData::Dumper -e 'my $vs = version->parse("v1.02_03");
print Data::Dumper->Dumper($vs)'
$VAR1 = 'Data::Dumper';
$VAR2 = bless( {
'qv' => 1,
'alpha' => 1,
'original' => 'v1.02_03',
'version' => [
1,
2,
3
]
}, 'version' );
As you can see declare(), which is an alias for qv(), parses the same
string consistently with or without a leading 'v', but parse()/new()
acts differently whether the leading 'v' is there or not.
Hope this helps...