This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
overload.pm: add a missing 'exists'
[perl5.git] / lib / overload.pm
index 73c8202..ba56314 100644 (file)
@@ -1,6 +1,6 @@
 package overload;
 
-our $VERSION = '1.24';
+our $VERSION = '1.28';
 
 %ops = (
     with_assign         => "+ - * / % ** << >> x .",
@@ -21,9 +21,7 @@ our $VERSION = '1.24';
 );
 
 my %ops_seen;
-for $category (keys %ops) {
-    $ops_seen{$_}++ for (split /\s+/, $ops{$category});
-}
+@ops_seen{ map split(/ /), values %ops } = ();
 
 sub nil {}
 
@@ -40,7 +38,7 @@ sub OVERLOAD {
       }
     } else {
       warnings::warnif("overload arg '$_' is invalid")
-        unless $ops_seen{$_};
+        unless exists $ops_seen{$_};
       $sub = $arg{$_};
       if (not ref $sub) {
        $ {$package . "::(" . $_} = $sub;
@@ -65,7 +63,7 @@ sub unimport {
   *{$package . "::(("} = \&nil;
   for (@_) {
       warnings::warnif("overload arg '$_' is invalid")
-        unless $ops_seen{$_};
+        unless exists $ops_seen{$_};
       delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_};
   }
 }
@@ -252,7 +250,9 @@ illustrates the calling conventions:
     # * may recurse once - see table below
 
 Three arguments are passed to all subroutines specified in the
-C<use overload> directive (with one exception - see L</nomethod>).
+C<use overload> directive (with exceptions - see below, particularly
+L</nomethod>).
+
 The first of these is the operand providing the overloaded
 operator implementation -
 in this case, the object whose C<minus()> method is being called.
@@ -310,6 +310,12 @@ An appropriate implementation of C<--> might look like
         # ...
     sub decr { --${$_[0]}; }
 
+If the experimental "bitwise" feature is enabled (see L<feature>), a fifth
+TRUE argument is passed to subroutines handling C<&>, C<|>, C<^> and C<~>.
+This indicates that the caller is expecting numeric behaviour.  The fourth
+argument will be C<undef>, as that position (C<$_[3]>) is reserved for use
+by L</nomethod>.
+
 =head3 Mathemagic, Mutators, and Copy Constructors
 
 The term 'mathemagic' describes the overloaded implementation
@@ -375,6 +381,7 @@ hash C<%overload::ops>:
 Most of the overloadable operators map one-to-one to these keys.
 Exceptions, including additional overloadable operations not
 apparent from this hash, are included in the notes which follow.
+This list is subject to growth over time.
 
 A warning is issued if an attempt is made to register an operator not found
 above.
@@ -407,7 +414,7 @@ evaluating an expression.
 =item * I<Assignments>
 
     +=  -=  *=  /=  %=  **=  <<=  >>=  x=  .=
-    &=  |=  ^=
+    &=  |=  ^=  &.=  |.=  ^.=
 
 Simple assignment is not overloadable (the C<'='> key is used
 for the L<Copy Constructor>).
@@ -437,7 +444,7 @@ even if C<$a> is a scalar.
 =item * I<Non-mutators with a mutator variant>
 
      +  -  *  /  %  **  <<  >>  x  .
-     &  |  ^
+     &  |  ^  &.  |.  ^.
 
 As described L<above|"Calling Conventions and Magic Autogeneration">,
 Perl may call methods for operators like C<+> and C<&> in the course
@@ -650,9 +657,9 @@ to C<'-='> and C<'--'> above:
 And other assignment variations are analogous to
 C<'+='> and C<'-='> (and similar to C<'.='> and C<'x='> above):
 
-              operator ||  *= /= %= **= <<= >>= &= ^= |=
-    -------------------||--------------------------------
-    autogenerated from ||  *  /  %  **  <<  >>  &  ^  |
+              operator ||  *= /= %= **= <<= >>= &= ^= |= &.= ^.= |.=
+    -------------------||-------------------------------------------
+    autogenerated from ||  *  /  %  **  <<  >>  &  ^  |  &.  ^.  |.
 
 Note also that the copy constructor (key C<'='>) may be
 autogenerated, but only for objects based on scalars.
@@ -668,7 +675,7 @@ expects.  The minimal set is:
 
     + - * / % ** << >> x
     <=> cmp
-    & | ^ ~
+    & | ^ ~ &. |. ^. ~.
     atan2 cos sin exp log sqrt int
     "" 0+ bool
     ~~
@@ -686,7 +693,8 @@ The specified function will be passed four parameters.
 The first three arguments coincide with those that would have been
 passed to the corresponding method if it had been defined.
 The fourth argument is the C<use overload> key for that missing
-method.
+method.  If the experimental "bitwise" feature is enabled (see L<feature>),
+a fifth TRUE argument is passed to subroutines handling C<&>, C<|>, C<^> and C<~> to indicate that the caller is expecting numeric behaviour.
 
 For example, if C<$a> is an object blessed into a package declaring
 
@@ -1054,7 +1062,7 @@ the stashes, which are rarely used directly, thus should not slow down
 Perl.)
 
 If a package uses overload, it carries a special flag.  This flag is also
-set when new function are defined or @ISA is modified.  There will be a
+set when new functions are defined or @ISA is modified.  There will be a
 slight speed penalty on the very first operation thereafter that supports
 overloading, while the overload tables are updated.  If there is no
 overloading present, the flag is turned off.  Thus the only speed penalty