summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-02-26 06:31:10 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-02-26 06:31:10 +0000
commit1571675a79745e7e3690e10ecdcf919c638d572b (patch)
treebcde2527119a19f04043c5a69c3f7e734361bad6 /toke.c
parentb46bc2b69fd0825253e7e513bb1c568567aa6ab0 (diff)
downloadperl-1571675a79745e7e3690e10ecdcf919c638d572b.tar.gz
support for version vectors in UNIVERSAL::VERSION(), so that
C<use Foo v1.2.3> etc., work; tests for the same TODO: XS_VERSION_BOOTCHECK needs to be revisited in light of this p4raw-id: //depot/perl@5265
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/toke.c b/toke.c
index 5347ecd0de..e18a4c8df8 100644
--- a/toke.c
+++ b/toke.c
@@ -812,6 +812,31 @@ S_force_ident(pTHX_ register char *s, int kind)
}
}
+NV
+Perl_str_to_version(pTHX_ SV *sv)
+{
+ NV retval = 0.0;
+ NV nshift = 1.0;
+ STRLEN len;
+ char *start = SvPVx(sv,len);
+ bool utf = SvUTF8(sv);
+ char *end = start + len;
+ while (start < end) {
+ I32 skip;
+ UV n;
+ if (utf)
+ n = utf8_to_uv((U8*)start, &skip);
+ else {
+ n = *(U8*)start;
+ skip = 1;
+ }
+ retval += ((NV)n)/nshift;
+ start += skip;
+ nshift *= 1000;
+ }
+ return retval;
+}
+
/*
* S_force_version
* Forces the next token to be a version number.
@@ -833,12 +858,12 @@ S_force_version(pTHX_ char *s)
if (*d == ';' || isSPACE(*d) || *d == '}' || !*d) {
SV *ver;
s = scan_num(s);
- /* real VERSION number -- GBARR */
version = yylval.opval;
ver = cSVOPx(version)->op_sv;
if (SvPOK(ver) && !SvNIOK(ver)) {
- SvUPGRADE(ver, SVt_PVIV);
- SvIOKp_on(ver); /* hint that it is a version */
+ SvUPGRADE(ver, SVt_PVNV);
+ SvNVX(ver) = str_to_version(ver);
+ SvNOK_on(ver); /* hint that it is a version */
}
}
}