This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
use semicolon to separate statements
[perl5.git] / lib / overload.pm
index 4a1912c..30f810b 100644 (file)
@@ -1,6 +1,6 @@
 package overload;
 
-our $VERSION = '1.26';
+our $VERSION = '1.31';
 
 %ops = (
     with_assign         => "+ - * / % ** << >> x .",
@@ -21,9 +21,7 @@ our $VERSION = '1.26';
 );
 
 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' ? '()' : "(" .$_};
   }
 }
@@ -213,7 +211,7 @@ To overload built-in functions, see L<perlsub/Overriding Built-in Functions> ins
 =head3 Declaration
 
 Arguments of the C<use overload> directive are (key, value) pairs.
-For the full set of legal keys, see L<Overloadable Operations> below.
+For the full set of legal keys, see L</Overloadable Operations> below.
 
 Operator implementations (the values) can be subroutines,
 references to subroutines, or anonymous subroutines
@@ -276,7 +274,7 @@ For example, if C<$x> and C<$y> are C<Number>s:
 
 Perl may also use C<minus()> to implement other operators which
 have not been specified in the C<use overload> directive,
-according to the rules for L<Magic Autogeneration> described later.
+according to the rules for L</Magic Autogeneration> described later.
 For example, the C<use overload> above declared no subroutine
 for any of the operators C<-->, C<neg> (the overload key for
 unary minus), or C<-=>.  Thus
@@ -302,7 +300,7 @@ only to return the result of the subtraction:
 Perl takes care of the assignment to $x.
 In fact, such methods should I<not> modify their operands,
 even if C<undef> is passed as the third argument
-(see L<Overloadable Operations>).
+(see L</Overloadable Operations>).
 
 The same is not true of implementations of C<++> and C<-->:
 these are expected to modify their operand.
@@ -312,7 +310,7 @@ An appropriate implementation of C<--> might look like
         # ...
     sub decr { --${$_[0]}; }
 
-If the experimental "bitwise" feature is enabled (see L<feature>), a fifth
+If the "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
@@ -356,7 +354,7 @@ arithmetic metaphor.
 Note: the preceding paragraph describes what happens when
 Perl autogenerates the copy constructor for an object based
 on a scalar.
-For other cases, see L<Copy Constructor>.
+For other cases, see L</Copy Constructor>.
 
 =head2 Overloadable Operations
 
@@ -419,7 +417,7 @@ evaluating an expression.
     &=  |=  ^=  &.=  |.=  ^.=
 
 Simple assignment is not overloadable (the C<'='> key is used
-for the L<Copy Constructor>).
+for the L</Copy Constructor>).
 Perl does have a way to make assignments to an object do whatever
 you want, but this involves using tie(), not overload -
 see L<perlfunc/tie> and the L</COOKBOOK> examples below.
@@ -577,7 +575,7 @@ then it will not be called again - avoiding infinite recursion.
 
     nomethod  fallback  =
 
-See L<Special Keys for C<use overload>>.
+See L</Special Keys for C<use overload>>.
 
 =back
 
@@ -665,7 +663,7 @@ C<'+='> and C<'-='> (and similar to C<'.='> and C<'x='> above):
 
 Note also that the copy constructor (key C<'='>) may be
 autogenerated, but only for objects based on scalars.
-See L<Copy Constructor>.
+See L</Copy Constructor>.
 
 =head3 Minimal Set of Overloaded Operations
 
@@ -695,7 +693,7 @@ 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.  If the experimental "bitwise" feature is enabled (see L<feature>),
+method.  If the "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
@@ -711,7 +709,7 @@ C<'+'>) result in a call
 
     catch_all($a, 3, 1, '+')
 
-See L<How Perl Chooses an Operator Implementation>.
+See L</How Perl Chooses an Operator Implementation>.
 
 =head3 C<fallback>
 
@@ -725,7 +723,7 @@ operator.
 
     use overload "fallback" => 0, # ... ;
 
-This disables L<Magic Autogeneration>.
+This disables L</Magic Autogeneration>.
 
 =item * C<undef>
 
@@ -739,12 +737,12 @@ autogenerated then, instead of issuing an error message, Perl
 is allowed to revert to what it would have done for that
 operator if there had been no C<use overload> directive.
 
-Note: in most cases, particularly the L<Copy Constructor>,
+Note: in most cases, particularly the L</Copy Constructor>,
 this is unlikely to be appropriate behaviour.
 
 =back
 
-See L<How Perl Chooses an Operator Implementation>.
+See L</How Perl Chooses an Operator Implementation>.
 
 =head3 Copy Constructor
 
@@ -892,7 +890,7 @@ on the type of their operands.
 As there is no way to instruct Perl to treat the operands as, e.g.,
 numbers instead of strings, the result here may not be what you
 expect.
-See L<BUGS AND PITFALLS>.
+See L</BUGS AND PITFALLS>.
 
 =head2 Losing Overloading
 
@@ -1415,12 +1413,12 @@ the tables of operations, and change the code which fills %subr to
   }
 
 Since subroutines implementing assignment operators are not required
-to modify their operands (see L<Overloadable Operations> above),
+to modify their operands (see L</Overloadable Operations> above),
 we do not need anything special to make C<+=> and friends work,
 besides adding these operators to %subr and defining a copy
 constructor (needed since Perl has no way to know that the
 implementation of C<'+='> does not mutate the argument -
-see L<Copy Constructor>).
+see L</Copy Constructor>).
 
 To implement a copy constructor, add C<< '=' => \&cpy >> to C<use overload>
 line, and code (this code assumes that mutators change things one level