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

version objects and stringification (again)

Thread Next
John Peacock
April 14, 2007 15:44
version objects and stringification (again)
Message ID:
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.


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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About