Skip Menu |

This queue is for tickets about the version CPAN distribution.

Report information
The Basics
Id: 58084
Status: rejected
Priority: 0/
Queue: version

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
kmx [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Numifying dev version (e.g. '1.2.3_4') does not return a number
Hi,

according to my testing

version->parse('1.2.3_4')->numify

returns

1.002003_004

I am not saying it is a bug however I wanna ask if it is an expected behaviour as I was presuming in my code that return value of numify is always a number.

Thanks for any feedback.

--
kmx
Just for record - my workaround for this is

using:

eval(version->parse('1.2.3_4')->numify)

instead of

version->parse('1.2.3_4')->numify

--
kmx

Subject: Re: [rt.cpan.org #58084] Numifying dev version (e.g. '1.2.3_4') does not return a number
Date: Thu, 03 Jun 2010 09:27:27 -0400
To: bug-version [...] rt.cpan.org
From: John Peacock <john.peacock [...] havurah-software.org>
kmx via RT wrote: Show quoted text
> version->parse('1.2.3_4')->numify > > returns > > 1.002003_004 > > I am not saying it is a bug however I wanna ask if it is an expected behaviour > as I was presuming in my code that return value of numify is always a number.
That is a number, in the sense that Perl considers underscores invisible in bare numbers. I wanted to preserve the fact that the original version object was an alpha number, so that version->parse('1.2.3_4') != version->parse('1.2.3.4') For your purposes, the use of an eval wrapper may be completely appropriate (or not). In general, once a version object is created, you should leave it as a version object and perform any comparisons directly, so that the overloaded vcmp method is called. The only time you should force a particular representation, i.e. stringify() or numify() is ... hmmm, actually, I can't think of a good reason to do that. Why did you want to numify() the object in the first place? John
Show quoted text
> Why did you want to numify() the object in the first place?

I am storing the numifyied value into database (SQLite) - into a field of REAL type. I just need to have SQL operators =<> do the right numeric (float) comparison + things like ORDER BY to work. So basically I am doing comparison outside of perl.

The eval() way seems to be OK so far - maybe a shot info about this "feature" in doc would be enough.

--
kmx

Subject: Re: [rt.cpan.org #58084] Numifying dev version (e.g. '1.2.3_4') does not return a number
Date: Thu, 03 Jun 2010 12:06:10 -0400
To: bug-version [...] rt.cpan.org
From: John Peacock <john.peacock [...] havurah-software.org>
kmx via RT wrote: Show quoted text
> I am storing the numifyied value into database (SQLite) - into a field of REAL > type. I just need to have SQL operators =<> do the right numeric (float) > comparison + things like ORDER BY to work. So basically I am doing comparison > outside of perl.
If you store the numified representation as a string, and then do string comparisons, you will have the correct effect. Underscore will sort after numbers, so version->parse('1.2.3')->numify < version->parse('1.2.3_4')->numify and version->parse('1.2.3_4')->numify < version->parse('1.2.4')->numify which is what you really want to happen. One thing to note is that if the user does something silly like tries to compare version->parse('1.2.3.4')->numify < version->parse('1.2.3_4')->numify they may not get what they expect... John
Not a bug
On Thu Jun 03 09:27:44 2010, john.peacock@havurah- Show quoted text
> That is a number, in the sense that Perl considers underscores > invisible > in bare numbers. I wanted to preserve the fact that the original > version object was an alpha number, so that > > version->parse('1.2.3_4') != version->parse('1.2.3.4')
Yes and no. The parser accept a _ in a number, but anywhere else it isn't valid. So «1_000 + 0» is 1000, but «"1_000" + 0» is 1. Show quoted text
> In general, once a version object is created, you should leave it as a > version object and perform any comparisons directly, so that the > overloaded vcmp method is called.
Generally I'd agree, but if a user explicitly asks for a number, they should get a number IMNSHO. Show quoted text
> The only time you should force a > particular representation, i.e. stringify() or numify() is ... hmmm, > actually, I can't think of a good reason to do that.
Storing it outside of perl would be the most common reason. Leon