summaryrefslogtreecommitdiff
path: root/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
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')
-rw-r--r--pod/perldelta.pod9
-rw-r--r--pod/perldiag.pod6
-rw-r--r--pod/perlop.pod20
3 files changed, 35 insertions, 0 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 23d3fe7656..664881286c 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -25,6 +25,15 @@ XXX New core language features go here. Summarize user-visible core language
enhancements. Particularly prominent performance optimisations could go
here, but most should go in the L</Performance Enhancements> section.
+=head2 The isa Operator
+
+A new experimental infix operator called C<isa> tests whether a given object
+is an instance of a given class or a class derived from it:
+
+ if( $obj isa Package::Name ) { ... }
+
+For more detail see L<perlop/Class Instance Operator>.
+
[ List each enhancement as a =head2 entry ]
=head1 Security
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 465317bf92..593032610c 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -3262,6 +3262,12 @@ an anonymous subroutine, or a reference to a subroutine.
(W overload) You tried to overload a constant type the overload package is
unaware of.
+=item isa is experimental
+
+(S experimental::isa) This warning is emitted if you use the (C<isa>)
+operator. This operator is currently experimental and its behaviour may
+change in future releases of Perl.
+
=item -i used with no filenames on the command line, reading from STDIN
(S inplace) The C<-i> option was passed on the command line, indicating
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),