summaryrefslogtreecommitdiff
path: root/keywords.c
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 /keywords.c
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 'keywords.c')
-rw-r--r--keywords.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/keywords.c b/keywords.c
index 9fa30e616a..d503bc9c2d 100644
--- a/keywords.c
+++ b/keywords.c
@@ -203,7 +203,7 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
goto unknown;
}
- case 3: /* 28 tokens of length 3 */
+ case 3: /* 29 tokens of length 3 */
switch (name[0])
{
case 'E':
@@ -320,13 +320,27 @@ Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
goto unknown;
case 'i':
- if (name[1] == 'n' &&
- name[2] == 't')
- { /* int */
- return -KEY_int;
- }
+ switch (name[1])
+ {
+ case 'n':
+ if (name[2] == 't')
+ { /* int */
+ return -KEY_int;
+ }
- goto unknown;
+ goto unknown;
+
+ case 's':
+ if (name[2] == 'a')
+ { /* isa */
+ return (all_keywords || FEATURE_ISA_IS_ENABLED ? -KEY_isa : 0);
+ }
+
+ goto unknown;
+
+ default:
+ goto unknown;
+ }
case 'l':
if (name[1] == 'o' &&
@@ -3437,5 +3451,5 @@ unknown:
}
/* Generated from:
- * db0472e0ad4f44bd0816cad799d63b60d1bbd7e11cef40ea15bf0d00f69669f6 regen/keywords.pl
+ * f77998a5bc995c1b42d3d080de227ef5f11638bcd329367431d8f193aef2d3cc regen/keywords.pl
* ex: set ro: */