summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2009-08-22 20:43:00 +0100
committerDavid Mitchell <davem@iabyn.com>2009-08-22 20:43:00 +0100
commit0de1c906c34397b53c088e443cd0325d9c209649 (patch)
tree1a382db766f29499d74dbf748f92379dd78ef16e /lib
parent0e44158ce94d11dde580b3793579946c7d918b97 (diff)
downloadperl-0de1c906c34397b53c088e443cd0325d9c209649.tar.gz
better document smart match overloading
Diffstat (limited to 'lib')
-rw-r--r--lib/overload.pm25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/overload.pm b/lib/overload.pm
index 77908328ed..d5ac5ad073 100644
--- a/lib/overload.pm
+++ b/lib/overload.pm
@@ -455,6 +455,31 @@ The key C<"~~"> allows you to override the smart matching logic used by
the C<~~> operator and the switch construct (C<given>/C<when>). See
L<perlsyn/switch> and L<feature>.
+Unusually, overloading of the smart match operator does not automatically
+take precedence over normal smart match behaviour. In particular, in the
+following code:
+
+ package Foo;
+ use overload '~~' => 'match';
+
+ my $obj = Foo->new();
+ $obj ~~ [ 1,2,3 ];
+
+the smart match does I<not> invoke the method call like this:
+
+ $obj->match([1,2,3],0);
+
+rather, the smart match distributive rule takes precedence, so $obj is
+smart matched against each array element in turn until a match is found,
+so you may see between one and three of these calls instead:
+
+ $obj->match(1,0);
+ $obj->match(2,0);
+ $obj->match(3,0);
+
+Consult the match table in L<perlsyn/"Smart matching in detail"> for
+details of when overloading is invoked.
+
=item * I<Dereferencing>
'${}', '@{}', '%{}', '&{}', '*{}'.