summaryrefslogtreecommitdiff
path: root/feature.h
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2019-10-23 19:00:38 +0100
committerPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2019-12-09 23:19:05 +0000
commit813e85a03dc214f719dc8248bda36156897b0757 (patch)
tree9e3c12a41469a967477219e0d0a670ab593618d2 /feature.h
parente139e9c0aa8151ab29e98bb9f3216ee7a14abe4d (diff)
downloadperl-813e85a03dc214f719dc8248bda36156897b0757.tar.gz
Add the `isa` operator
Adds a new infix operator named `isa`, with the semantics that $x isa SomeClass is true if and only if `$x` is a blessed object reference that is either `SomeClass` directly, or includes the class somewhere in its @ISA hierarchy. It is false without warning or error for non-references or non-blessed references. This operator respects `->isa` method overloading, and is intended to replace boilerplate code such as use Scalar::Util 'blessed'; blessed($x) and $x->isa("SomeClass")
Diffstat (limited to 'feature.h')
-rw-r--r--feature.h31
1 files changed, 23 insertions, 8 deletions
diff --git a/feature.h b/feature.h
index 2b5b656bb8..0044b06b42 100644
--- a/feature.h
+++ b/feature.h
@@ -17,14 +17,15 @@
#define FEATURE_MYREF_BIT 0x0004
#define FEATURE_EVALBYTES_BIT 0x0008
#define FEATURE_FC_BIT 0x0010
-#define FEATURE_POSTDEREF_QQ_BIT 0x0020
-#define FEATURE_REFALIASING_BIT 0x0040
-#define FEATURE_SAY_BIT 0x0080
-#define FEATURE_SIGNATURES_BIT 0x0100
-#define FEATURE_STATE_BIT 0x0200
-#define FEATURE_SWITCH_BIT 0x0400
-#define FEATURE_UNIEVAL_BIT 0x0800
-#define FEATURE_UNICODE_BIT 0x1000
+#define FEATURE_ISA_BIT 0x0020
+#define FEATURE_POSTDEREF_QQ_BIT 0x0040
+#define FEATURE_REFALIASING_BIT 0x0080
+#define FEATURE_SAY_BIT 0x0100
+#define FEATURE_SIGNATURES_BIT 0x0200
+#define FEATURE_STATE_BIT 0x0400
+#define FEATURE_SWITCH_BIT 0x0800
+#define FEATURE_UNIEVAL_BIT 0x1000
+#define FEATURE_UNICODE_BIT 0x2000
#define FEATURE_BUNDLE_DEFAULT 0
#define FEATURE_BUNDLE_510 1
@@ -54,6 +55,12 @@
FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
)
+#define FEATURE_ISA_IS_ENABLED \
+ ( \
+ CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
+ FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
+ )
+
#define FEATURE_SAY_IS_ENABLED \
( \
(CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
@@ -236,6 +243,14 @@ S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
}
return;
+ case 'i':
+ if (keylen == sizeof("feature_isa")-1
+ && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
+ mask = FEATURE_ISA_BIT;
+ break;
+ }
+ return;
+
case 'm':
if (keylen == sizeof("feature_myref")-1
&& memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {