diff options
author | Adriano Ferreira <a.r.ferreira@gmail.com> | 2006-11-23 15:43:12 -0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-11-24 15:03:55 +0000 |
commit | 6dd857431f51e510fbff1fc7f983b04624551018 (patch) | |
tree | a6955350025ed5f5d58ef733f52da952c2022c0a /lib/overload.t | |
parent | 150d06de2e4cba0da08555d83988a89acd541d70 (diff) | |
download | perl-6dd857431f51e510fbff1fc7f983b04624551018.tar.gz |
[perl #36689] &=, |= and ^= overloads are nbot documented
From: "Adriano Rodrigues" <a.r.ferreira@gmail.com>
Message-ID: <73ddeb6c0611231143y1e3461dbqf30f5fce16698b5c@mail.gmail.com>
p4raw-id: //depot/perl@29373
Diffstat (limited to 'lib/overload.t')
-rw-r--r-- | lib/overload.t | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t index 6dafa07576..ade87f2926 100644 --- a/lib/overload.t +++ b/lib/overload.t @@ -47,7 +47,7 @@ sub numify { 0 + "${$_[0]}" } # Not needed, additional overhead package main; $| = 1; -use Test::More tests => 509; +use Test::More tests => 512; $a = new Oscalar "087"; @@ -1253,3 +1253,36 @@ foreach my $op (qw(<=> == != < <= > >=)) { undef $obj; is ($ref, undef); } + +{ + package bit; + # bit operations have overloadable assignment variants too + + sub new { bless \$_[1], $_[0] } + + use overload + "&=" => sub { bit->new($_[0]->val . ' & ' . $_[1]->val) }, + "^=" => sub { bit->new($_[0]->val . ' ^ ' . $_[1]->val) }, + "|" => sub { bit->new($_[0]->val . ' | ' . $_[1]->val) }, # |= by fallback + ; + + sub val { ${$_[0]} } + + package main; + + my $a = bit->new(my $va = 'a'); + my $b = bit->new(my $vb = 'b'); + + $a &= $b; + is($a->val, 'a & b', "overloaded &= works"); + + my $c = bit->new(my $vc = 'c'); + + $b ^= $c; + is($b->val, 'b ^ c', "overloaded ^= works"); + + my $d = bit->new(my $vd = 'd'); + + $c |= $d; + is($c->val, 'c | d', "overloaded |= (by fallback) works"); +} |