summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorJohn Peacock <jpeacock@cpan.org>2011-12-06 20:55:09 -0500
committerDavid Golden <dagolden@cpan.org>2011-12-09 14:59:04 -0500
commit573a19fb2c79f41cfc7f3db5a8ad14e14a4dccf9 (patch)
treee7c0c975264052c4d7fb48acafc9a91c8566ebc2 /universal.c
parenta97f6d148c766c74f3c3200d95d9fbf569067b45 (diff)
downloadperl-573a19fb2c79f41cfc7f3db5a8ad14e14a4dccf9.tar.gz
Use syntax from perlguts for testing objects
The following paragraph is in perlguts.pod: To check if you've got an object derived from a specific class you have to write: if (sv_isobject(sv) && sv_derived_from(sv, class)) { ... } which does the right thing with magical things like tied scalars. Signed-off-by: David Golden <dagolden@cpan.org>
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/universal.c b/universal.c
index 563761eb83..a109e7d2fe 100644
--- a/universal.c
+++ b/universal.c
@@ -425,7 +425,7 @@ XS(XS_UNIVERSAL_VERSION)
SV * const nsv = sv_newmortal();
sv_setsv(nsv, sv);
sv = nsv;
- if ( !sv_derived_from(sv, "version") || !SvROK(sv))
+ if ( !sv_isobject(sv) || !sv_derived_from(sv, "version"))
upg_version(sv, FALSE);
undef = NULL;
@@ -452,7 +452,7 @@ XS(XS_UNIVERSAL_VERSION)
}
}
- if ( !sv_derived_from(req, "version") || !SvROK(req)) {
+ if ( !sv_isobject(req) || !sv_derived_from(req, "version")) {
/* req may very well be R/O, so create a new object */
req = sv_2mortal( new_version(req) );
}
@@ -538,7 +538,7 @@ XS(XS_version_stringify)
{
SV * lobj = ST(0);
- if (sv_derived_from(lobj, "version") && SvROK(lobj)) {
+ if (sv_isobject(lobj) && sv_derived_from(lobj, "version")) {
lobj = SvRV(lobj);
}
else
@@ -561,7 +561,7 @@ XS(XS_version_numify)
{
SV * lobj = ST(0);
- if (sv_derived_from(lobj, "version") && SvROK(lobj)) {
+ if (sv_isobject(lobj) && sv_derived_from(lobj, "version")) {
lobj = SvRV(lobj);
}
else
@@ -584,7 +584,7 @@ XS(XS_version_normal)
{
SV * lobj = ST(0);
- if (sv_derived_from(lobj, "version") && SvROK(lobj)) {
+ if (sv_isobject(lobj) && sv_derived_from(lobj, "version")) {
lobj = SvRV(lobj);
}
else
@@ -607,7 +607,7 @@ XS(XS_version_vcmp)
{
SV * lobj = ST(0);
- if (sv_derived_from(lobj, "version") && SvROK(lobj)) {
+ if (sv_isobject(lobj) && sv_derived_from(lobj, "version")) {
lobj = SvRV(lobj);
}
else
@@ -619,7 +619,7 @@ XS(XS_version_vcmp)
SV * robj = ST(1);
const IV swap = (IV)SvIV(ST(2));
- if ( ! sv_derived_from(robj, "version") || !SvROK(robj) )
+ if ( !sv_isobject(robj) || !sv_derived_from(robj, "version") )
{
robj = new_version(SvOK(robj) ? robj : newSVpvs_flags("0", SVs_TEMP));
sv_2mortal(robj);
@@ -650,7 +650,7 @@ XS(XS_version_boolean)
if (items < 1)
croak_xs_usage(cv, "lobj, ...");
SP -= items;
- if (sv_derived_from(ST(0), "version") && SvROK(ST(0))) {
+ if (sv_isobject(ST(0)) && sv_derived_from(ST(0), "version")) {
SV * const lobj = SvRV(ST(0));
SV * const rs = newSViv( vcmp(lobj,new_version(newSVpvs("0"))) );
mPUSHs(rs);
@@ -667,7 +667,7 @@ XS(XS_version_noop)
dXSARGS;
if (items < 1)
croak_xs_usage(cv, "lobj, ...");
- if (sv_derived_from(ST(0), "version") && SvROK(ST(0)))
+ if (sv_isobject(ST(0)) && sv_derived_from(ST(0), "version"))
Perl_croak(aTHX_ "operation not supported with version object");
else
Perl_croak(aTHX_ "lobj is not of type version");
@@ -683,7 +683,7 @@ XS(XS_version_is_alpha)
if (items != 1)
croak_xs_usage(cv, "lobj");
SP -= items;
- if (sv_derived_from(ST(0), "version") && SvROK(ST(0))) {
+ if (sv_isobject(ST(0)) && sv_derived_from(ST(0), "version")) {
SV * const lobj = ST(0);
if ( hv_exists(MUTABLE_HV(SvRV(lobj)), "alpha", 5 ) )
XSRETURN_YES;
@@ -745,7 +745,7 @@ XS(XS_version_is_qv)
if (items != 1)
croak_xs_usage(cv, "lobj");
SP -= items;
- if (sv_derived_from(ST(0), "version") && SvROK(ST(0))) {
+ if (sv_isobject(ST(0)) && sv_derived_from(ST(0), "version")) {
SV * const lobj = ST(0);
if ( hv_exists(MUTABLE_HV(SvRV(lobj)), "qv", 2 ) )
XSRETURN_YES;