summaryrefslogtreecommitdiff
path: root/pod/perlop.pod
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 /pod/perlop.pod
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 'pod/perlop.pod')
-rw-r--r--pod/perlop.pod20
1 files changed, 20 insertions, 0 deletions
diff --git a/pod/perlop.pod b/pod/perlop.pod
index c4eecd6c79..57bda73252 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -78,6 +78,7 @@ values only, not array values.
nonassoc named unary operators
nonassoc < > <= >= lt gt le ge
nonassoc == != <=> eq ne cmp ~~
+ nonassoc isa
left &
left | ^
left &&
@@ -575,6 +576,25 @@ function, available in Perl v5.16 or later:
if ( fc($x) eq fc($y) ) { ... }
+=head2 Class Instance Operator
+X<isa operator>
+
+Binary C<isa> evaluates to true when left argument is an object instance of
+the class (or a subclass derived from that class) given by the right argument.
+If the left argument is not defined, not a blessed object instance, or does
+not derive from the class given by the right argument, the operator evaluates
+as false. The right argument may give the class either as a barename or a
+scalar expression that yields a string class name:
+
+ if( $obj isa Some::Class ) { ... }
+
+ if( $obj isa "Different::Class" ) { ... }
+ if( $obj isa $name_of_class ) { ... }
+
+This is an experimental feature and is available from Perl 5.31.6 when enabled
+by C<use feature 'isa'>. It emits a warning in the C<experimental::isa>
+category.
+
=head2 Smartmatch Operator
First available in Perl 5.10.1 (the 5.10.0 version behaved differently),