Produce right error msg for $ver < "version"
authorFather Chrysostomos <sprout@cpan.org>
Wed, 23 Nov 2011 17:48:01 +0000 (09:48 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 24 Nov 2011 09:45:28 +0000 (01:45 -0800)
"version" was being treated as a version object and then failing
the validation check.  It should be treated as a string, just like
"versions":

$ perl5.15.4 -Ilib -e '$^V < "version"'
Invalid version object at -e line 1.

$ perl5.15.4 -Ilib -e '$^V < "versions"'
Invalid version format (dotted-decimal versions require at least three parts) at -e line 1.

See also perl #102586.

lib/version.t
universal.c

index da11023..ce46fa2 100644 (file)
@@ -328,6 +328,11 @@ sub BaseTests {
     $new_version = $CLASS->$method("1.1.999");
     ok ( $version > $new_version, '$version > $new_version' );
     
+    diag "test with version class names" unless $ENV{PERL_CORE};
+    $version = $CLASS->$method("v1.2.3");
+    eval { $version < $CLASS };
+    like $@, qr/^Invalid version format/, "error with $version < $CLASS";
+    
     # that which is not expressly permitted is forbidden
     diag "forbidden operations" unless $ENV{PERL_CORE};
     ok ( !eval { ++$version }, "noop ++" );
index 57650e8..aeefca8 100644 (file)
@@ -615,7 +615,7 @@ XS(XS_version_vcmp)
               SV * robj = ST(1);
               const IV  swap = (IV)SvIV(ST(2));
 
-              if ( ! sv_derived_from(robj, "version") )
+              if ( ! sv_derived_from(robj, "version") || !SvROK(robj) )
               {
                    robj = new_version(SvOK(robj) ? robj : newSVpvs_flags("0", SVs_TEMP));
                    sv_2mortal(robj);