summaryrefslogtreecommitdiff
path: root/lib/overload.pm
diff options
context:
space:
mode:
authorjkeenan <jkeenan@cpan.org>2012-01-15 09:07:13 -0500
committerFather Chrysostomos <sprout@cpan.org>2012-01-16 12:51:43 -0800
commit9d51dcee04c4fd5387333086cac218960f210622 (patch)
treeded39054dce332f29395f7716cce78dd9f48e253 /lib/overload.pm
parent604a99bd464c92d77ef2476ab9779cddb72339c4 (diff)
downloadperl-9d51dcee04c4fd5387333086cac218960f210622.tar.gz
Emit a warning if an attempt is made to overload an invalid (e.g., misspelled) operator. For RT #74098.
Diffstat (limited to 'lib/overload.pm')
-rw-r--r--lib/overload.pm47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/overload.pm b/lib/overload.pm
index 1f9f461da1..8af28e547d 100644
--- a/lib/overload.pm
+++ b/lib/overload.pm
@@ -1,12 +1,38 @@
package overload;
-our $VERSION = '1.17';
+our $VERSION = '1.18';
+
+%ops = (
+ with_assign => "+ - * / % ** << >> x .",
+ assign => "+= -= *= /= %= **= <<= >>= x= .=",
+ num_comparison => "< <= > >= == !=",
+ '3way_comparison' => "<=> cmp",
+ str_comparison => "lt le gt ge eq ne",
+ binary => '& &= | |= ^ ^=',
+ unary => "neg ! ~",
+ mutators => '++ --',
+ func => "atan2 cos sin exp abs log sqrt int",
+ conversion => 'bool "" 0+ qr',
+ iterators => '<>',
+ filetest => "-X",
+ dereferencing => '${} @{} %{} &{} *{}',
+ matching => '~~',
+ special => 'nomethod fallback =',
+);
+
+%ops_seen;
+for $category (keys %ops) {
+ $ops_seen{$_}++ for (split /\s+/, $ops{$category});
+}
sub nil {}
sub OVERLOAD {
$package = shift;
my %arg = @_;
+ for (keys %arg) {
+ warn "overload arg '$_' is invalid" unless $ops_seen{$_};
+ }
my ($sub, $fb);
$ {$package . "::OVERLOAD"}{dummy}++; # Register with magic by touching.
$fb = ${$package . "::()"}; # preserve old fallback value RT#68196
@@ -128,22 +154,6 @@ sub mycan { # Real can would leave stubs.
'qr' => 0x10000, # HINT_NEW_RE
);
-%ops = ( with_assign => "+ - * / % ** << >> x .",
- assign => "+= -= *= /= %= **= <<= >>= x= .=",
- num_comparison => "< <= > >= == !=",
- '3way_comparison'=> "<=> cmp",
- str_comparison => "lt le gt ge eq ne",
- binary => '& &= | |= ^ ^=',
- unary => "neg ! ~",
- mutators => '++ --',
- func => "atan2 cos sin exp abs log sqrt int",
- conversion => 'bool "" 0+ qr',
- iterators => '<>',
- filetest => "-X",
- dereferencing => '${} @{} %{} &{} *{}',
- matching => '~~',
- special => 'nomethod fallback =');
-
use warnings::register;
sub constant {
# Arguments: what, sub
@@ -379,6 +389,9 @@ 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.
+A warning is issued if an attempt is made to register an operator not found
+above.
+
=over 5
=item * C<not>