develooper Front page | perl.perl5.porters | Postings from April 2007

version objects and stringification (again)

Thread Next
From:
John Peacock
Date:
April 14, 2007 15:44
Subject:
version objects and stringification (again)
Message ID:
4621595F.4020508@rowman.com
I released version-0.72 to CPAN the other morning and just today I realized that
I missed one piece of the puzzle:  __PACKAGE__->VERSION() returns a scalar, not
an object, so it must be /also/ return the stringified version.  Unfortunately,
a long time ago, the consensus was that the replacement UNIVERSAL::VERSION
should return the numified form for extended versions, i.e. 5.008001 not v5.8.1.
 But this conflicts with the current argument that trailing zeros are bad, so
what is it that I should return from UNIVERSAL::VERSION?

Before you start hammering away on the details, understand this:  new() creates
a version object that is either numeric (single decimal place) or extended
(multiple decimal places).  qv(), on the other hand, *always* creates extended
versions, even if it wouldn't otherwise (i.e. qv("1.2") == qv("1.2.0").  So the
initializer string to qv() cannot be saved away for later because it might not
be the same version, i.e. qv("1.2") != version->new("1.2").

I'm inclined to simply state that UNIVERSAL::VERSION returns the stringification
of the version object, which will be either the original string used to
initialize it (in the case of numeric versions), or the normalized form for
extended versions (which might be different from what was used to initialize
it).  I can't think of a better way to handle it other than making it more
complicated[1] and harder to explain.

John

1. For example:

Objects created using version->new() will store their intial string and use that
exclusively with stringified or as returned by UNIVERSAL::VERSION, whether they
are numeric or extended versions.

On the other hand, objects created with qv() will always return the normalized
form for both stringification and UNIVERSAL::VERSION.

-- 
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Blvd
Suite H
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About