Subject: | version->new(undef, '1.2') version::new(undef, '1.2') questionable behavior |
I was trying to clean up issues mentioned in https://rt.perl.org/Ticket/Display.html?id=115660#txn-1169402 by me, I read http://search.cpan.org/~jpeacock/version-0.9907/lib/version/Internals.pod#Object_Methods but I didn't see it specifying what will happen in the 1st example below. Currently the 1st example below complicates the new XS code I'm working on, logic tree wise. I've attached a patch of what I have so far, but none of the examples below were run using it. Also note the last example doesn't have a prefixed "v".
------------------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new(undef, 1.2)"
0
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new('rev', 1.2)"
v1.2
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new(qw!rev 1.2!)"
v1.2
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new(qw!1.2!)"
1.2
C:\Documents and Settings\Owner\Desktop\cpan libs\version>
------------------------------------------------------
Also here is another edge case I have no clue on what should happen. Notice the XS vs PP difference, 1 fatal errors, the other doesn't.
-------------------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new('rev', 'v1.2')"
Invalid version format (dotted-decimal versions require at least three parts) at
-e line 1.
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version->new(undef, 'v1.2')"
0
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp->new('rev', '1.2')"
Use of "goto" to jump into a construct is deprecated at C:/perl519/site/lib/vers
ion/vpp.pm line 258.
v1.2
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp->new(undef, '1.2')"
0
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp->new(undef, 'v1.2')"
0
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp->new('rev', 'v1.2')"
v1.2
C:\Documents and Settings\Owner\Desktop\cpan libs\version>
-------------------------------------------------------
Some more PP vs XS differences regarding passing garbage class names (AKA undef),
-------------------------------------------------------
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version::new('rev', '1.2')"
rev=HASH(0x369c94)
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version::new(undef, '1.2')"
main=HASH(0x369c94)
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion -E" say
version::new(undef, undef, '1.2')"
main=HASH(0x369cc4)
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp::new(undef, undef, '1.2')"
Usage: version::new(class, version) at -e line 1.
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp::new(undef, '1.2')"
Usage: version::new(class, version) at -e line 1.
C:\Documents and Settings\Owner\Desktop\cpan libs\version>perl -Mversion::vpp -E
" say version::vpp::new('rev', '1.2')"
rev=HASH(0x369024)
C:\Documents and Settings\Owner\Desktop\cpan libs\version>
-----------------------------------------------------------------------
Subject: | 0002-WIP-version_new.patch |
From d4a043abe2e939ddc092f168e28fbf90074ce73d Mon Sep 17 00:00:00 2001
From: bulk88 <bulk88@hotmail.com>
Date: Fri, 24 Jan 2014 10:23:16 -0500
Subject: [PATCH 2/2] WIP version_new
---
vutil/vxs.inc | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/vutil/vxs.inc b/vutil/vxs.inc
index 0a02056..bef2d72 100644
--- a/vutil/vxs.inc
+++ b/vutil/vxs.inc
@@ -173,7 +173,7 @@ VXS(version_new)
{
dVAR;
dXSARGS;
- SV *vs = items ? ST(1) : &PL_sv_undef;
+ SV *vs;
SV *rv;
const char * classname = "";
STRLEN len;
@@ -186,8 +186,13 @@ VXS(version_new)
if (items > 3 || items == 0)
Perl_croak(aTHX_ "Usage: version::new(class, version)");
+ if(items >= 2) {
+ vs = ST(1);
/* Just in case this is something like a tied hash */
- SvGETMAGIC(vs);
+ SvGETMAGIC(vs);
+ } else {
+ vs =&PL_sv_undef; /* dont do SvOK on this! use a goto instead???? */
+ }
if ( items == 1 || ! SvOK(vs) ) { /* no param or explicit undef */
/* create empty object */
--
1.7.9.msysgit.0