package overload;
-our $VERSION = '1.26';
+our $VERSION = '1.31';
%ops = (
with_assign => "+ - * / % ** << >> x .",
);
my %ops_seen;
-for $category (keys %ops) {
- $ops_seen{$_}++ for (split /\s+/, $ops{$category});
-}
+@ops_seen{ map split(/ /), values %ops } = ();
sub nil {}
}
} else {
warnings::warnif("overload arg '$_' is invalid")
- unless $ops_seen{$_};
+ unless exists $ops_seen{$_};
$sub = $arg{$_};
if (not ref $sub) {
$ {$package . "::(" . $_} = $sub;
*{$package . "::(("} = \&nil;
for (@_) {
warnings::warnif("overload arg '$_' is invalid")
- unless $ops_seen{$_};
+ unless exists $ops_seen{$_};
delete $ {$package . "::"}{$_ eq 'fallback' ? '()' : "(" .$_};
}
}
=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
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
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.
# ...
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
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
&= |= ^= &.= |.= ^.=
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.
nomethod fallback =
-See L<Special Keys for C<use overload>>.
+See L</Special Keys for C<use overload>>.
=back
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
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
catch_all($a, 3, 1, '+')
-See L<How Perl Chooses an Operator Implementation>.
+See L</How Perl Chooses an Operator Implementation>.
=head3 C<fallback>
use overload "fallback" => 0, # ... ;
-This disables L<Magic Autogeneration>.
+This disables L</Magic Autogeneration>.
=item * C<undef>
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
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
}
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