diff options
author | Father Chrysostomos <sprout@cpan.org> | 2015-01-09 08:45:28 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2015-01-31 22:03:53 -0800 |
commit | 636ac8fc9ac210e786fda679ad294c918022d0c5 (patch) | |
tree | da4fcc2499b4f943897103e8852d39ecf924cf11 /lib | |
parent | 594a52e669cf40aeb3e1f610fad70e3f919e8e10 (diff) | |
download | perl-636ac8fc9ac210e786fda679ad294c918022d0c5.tar.gz |
5th arg to indicate numeric bitwise overloading
Diffstat (limited to 'lib')
-rw-r--r-- | lib/overload.t | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/overload.t b/lib/overload.t index 9e9798c59d..6bbbb0b9d3 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -48,7 +48,7 @@ package main; $| = 1; BEGIN { require './test.pl' } -plan tests => 5200; +plan tests => 5215; use Scalar::Util qw(tainted); @@ -2759,7 +2759,11 @@ package bitops { use overload do { my %o; for my $o (qw(& | ^ ~ &. |. ^. ~. &= |= ^= &.= |.= ^.=)) { - $o{$o} = sub { push @o, $o; $_[0] } + $o{$o} = sub { + ::ok !defined $_[3], "undef (or nonexistent) arg 3 for $o"; + push @o, $o, scalar @_, $_[4]//'u'; + $_[0] + } } %o, '=' => sub { bless [] }; } @@ -2781,9 +2785,37 @@ package bitops { $o &.= 0; $o |.= 0; $o ^.= 0; - is "@bitops::o", '& | ^ ~ &. |. ^. ~. &= |= ^= &.= |.= ^.=', + # elems are in triplets: op, length of @_, numeric? (1/u for y/n) + is "@bitops::o", '& 5 1 | 5 1 ^ 5 1 ~ 5 1 &. 3 u |. 3 u ^. 3 u ~. 3 u ' . '&= 5 1 |= 5 1 ^= 5 1 &.= 3 u |.= 3 u ^.= 3 u', 'experimental "bitwise" ops' } +package bitops2 { + our @o; + use overload + nomethod => sub { push @o, $_[3], scalar @_, $_[4]//'u'; $_[0] }, + '=' => sub { bless [] }; +} +{ + use experimental 'bitwise'; + my $o = bless [], bitops2::; + $_ = $o & 0; + $_ = $o | 0; + $_ = $o ^ 0; + $_ = ~$o; + $_ = $o &. 0; + $_ = $o |. 0; + $_ = $o ^. 0; + $_ = ~.$o; + $o &= 0; + $o |= 0; + $o ^= 0; + $o &.= 0; + $o |.= 0; + $o ^.= 0; + # elems are in triplets: op, length of @_, numeric? (1/u for y/n) + is "@bitops2::o", '& 5 1 | 5 1 ^ 5 1 ~ 5 1 &. 4 u |. 4 u ^. 4 u ~. 4 u ' . '&= 5 1 |= 5 1 ^= 5 1 &.= 4 u |.= 4 u ^.= 4 u', + 'experimental "bitwise" ops with nomethod' +} { # undefining the overload stash -- KEEP THIS TEST LAST package ant; |