summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorJohn Peacock <jpeacock@rowman.com>2005-06-06 01:18:21 -0400
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-06-13 15:20:05 +0000
commit9137345a080bfc646c2f9440cdb7bd90b8b37428 (patch)
tree8569935efd39331a6e995344f060e00e2c6d6409 /universal.c
parent4d5ff0dd951920bb2d1547bff31c06ec7201d40a (diff)
downloadperl-9137345a080bfc646c2f9440cdb7bd90b8b37428.tar.gz
Bring bleadperl up to version.pm
Message-ID: <42A414DD.8090504@rowman.com> p4raw-id: //depot/perl@24823
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c76
1 files changed, 55 insertions, 21 deletions
diff --git a/universal.c b/universal.c
index 0a729e99d7..1564b59eaa 100644
--- a/universal.c
+++ b/universal.c
@@ -174,6 +174,7 @@ PERL_XS_EXPORT_C void XS_UNIVERSAL_VERSION(pTHX_ CV *cv);
XS(XS_version_new);
XS(XS_version_stringify);
XS(XS_version_numify);
+XS(XS_version_normal);
XS(XS_version_vcmp);
XS(XS_version_boolean);
#ifdef HASATTRIBUTE_NORETURN
@@ -218,6 +219,7 @@ Perl_boot_core_UNIVERSAL(pTHX)
newXS("version::stringify", XS_version_stringify, file);
newXS("version::(0+", XS_version_numify, file);
newXS("version::numify", XS_version_numify, file);
+ newXS("version::normal", XS_version_normal, file);
newXS("version::(cmp", XS_version_vcmp, file);
newXS("version::(<=>", XS_version_vcmp, file);
newXS("version::vcmp", XS_version_vcmp, file);
@@ -395,12 +397,32 @@ XS(XS_version_new)
Perl_croak(aTHX_ "Usage: version::new(class, version)");
SP -= items;
{
- const char *classname = SvPV_nolen_const(ST(0));
SV *vs = ST(1);
SV *rv;
- if (items == 3 )
- {
- vs = sv_newmortal();
+ const char *classname;
+
+ /* get the class if called as an object method */
+ if ( sv_isobject(ST(0)) ) {
+ classname = HvNAME(SvSTASH(SvRV(ST(0))));
+ }
+ else {
+ classname = (char *)SvPV_nolen(ST(0));
+ }
+
+ if ( items == 1 ) {
+ /* no parameter provided */
+ if ( sv_isobject(ST(0)) ) {
+ /* copy existing object */
+ vs = ST(0);
+ }
+ else {
+ /* create empty object */
+ vs = sv_newmortal();
+ sv_setpv(vs,"");
+ }
+ }
+ else if ( items == 3 ) {
+ vs = sv_newmortal();
Perl_sv_setpvf(aTHX_ vs,"v%s",SvPV_nolen_const(ST(2)));
}
@@ -424,8 +446,7 @@ XS(XS_version_stringify)
SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
@@ -447,8 +468,7 @@ XS(XS_version_numify)
SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
@@ -460,6 +480,28 @@ XS(XS_version_numify)
}
}
+XS(XS_version_normal)
+{
+ dXSARGS;
+ if (items < 1)
+ Perl_croak(aTHX_ "Usage: version::normal(lobj, ...)");
+ SP -= items;
+ {
+ SV * lobj = Nullsv;
+
+ if (sv_derived_from(ST(0), "version")) {
+ lobj = SvRV(ST(0));
+ }
+ else
+ Perl_croak(aTHX_ "lobj is not of type version");
+
+ PUSHs(sv_2mortal(vnormal(lobj)));
+
+ PUTBACK;
+ return;
+ }
+}
+
XS(XS_version_vcmp)
{
dXSARGS;
@@ -470,8 +512,7 @@ XS(XS_version_vcmp)
SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
@@ -515,9 +556,7 @@ XS(XS_version_boolean)
SV * lobj = Nullsv;
if (sv_derived_from(ST(0), "version")) {
- /* XXX If tmp serves a purpose, explain it. */
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
+ lobj = SvRV(ST(0));
}
else
Perl_croak(aTHX_ "lobj is not of type version");
@@ -556,17 +595,12 @@ XS(XS_version_is_alpha)
{
SV * lobj = Nullsv;
- if (sv_derived_from(ST(0), "version")) {
- /* XXX If tmp serves a purpose, explain it. */
- SV *tmp = SvRV(ST(0));
- lobj = tmp;
- }
+ if (sv_derived_from(ST(0), "version"))
+ lobj = ST(0);
else
Perl_croak(aTHX_ "lobj is not of type version");
{
- const I32 len = av_len((AV *)lobj);
- const I32 digit = SvIVX(*av_fetch((AV *)lobj, len, 0));
- if ( digit < 0 )
+ if ( hv_exists((HV*)SvRV(lobj), "alpha", 5 ) )
XSRETURN_YES;
else
XSRETURN_NO;