diff options
author | Larry Wall <lwall@scalpel.netlabs.com> | 1995-11-21 10:01:00 +1200 |
---|---|---|
committer | Larry <lwall@scalpel.netlabs.com> | 1995-11-21 10:01:00 +1200 |
commit | 4633a7c4bad06b471d9310620b7fe8ddd158cccd (patch) | |
tree | 37ebeb26a64f123784fd8fac6243b124767243b0 /t/op/overload.t | |
parent | 8e07c86ebc651fe92eb7e3b25f801f57cfb8dd6f (diff) | |
download | perl-4633a7c4bad06b471d9310620b7fe8ddd158cccd.tar.gz |
5.002 beta 1
If you're adventurous, have a look at
ftp://ftp.sems.com/pub/outgoing/perl5.0/perl5.002beta1.tar.gz
Many thanks to Andy for doing the integration.
Obviously, if you consult the bugs database, you'll note there are
still plenty of buglets that need fixing, and several enhancements that
I've intended to put in still haven't made it in (Hi, Tim and Ilya).
But I think it'll be pretty stable. And you can start to fiddle around
with prototypes (which are, of course, still totally undocumented).
Packrats, don't worry too much about readvertising this widely.
Nowadays we're on a T1 here, so our bandwidth is okay.
Have the appropriate amount of jollity.
Larry
Diffstat (limited to 't/op/overload.t')
-rw-r--r--[-rwxr-xr-x] | t/op/overload.t | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/t/op/overload.t b/t/op/overload.t index ab76492141..183cb273f7 100755..100644 --- a/t/op/overload.t +++ b/t/op/overload.t @@ -5,10 +5,9 @@ BEGIN { unshift @INC, './lib', '../lib'; } package Oscalar; - -%OVERLOAD = ( +use overload ( # Anonymous subroutines: -'+' => sub {new Oscalar ${$_[0]}+$_[1]}, +'+' => sub {new Oscalar $ {$_[0]}+$_[1]}, '-' => sub {new Oscalar $_[2]? $_[1]-${$_[0]} : ${$_[0]}-$_[1]}, '<=>' => sub {new Oscalar @@ -52,7 +51,8 @@ sub test { $a = new Oscalar "087"; $b= "$a"; -test (!defined ref $b); # 1 +# All test numbers in comments are off by 1. +# So much for hard-wiring them in :-) test ($b eq $a); # 2 test ($b eq "087"); # 3 test (ref $a eq "Oscalar"); # 4 @@ -92,7 +92,7 @@ test ( $a eq "087"); # 20 test ( $b eq "88"); # 21 test (ref $a eq "Oscalar"); # 22 -$Oscalar::OVERLOAD{'++'} = sub {${$_[0]}++;$_[0]}; +eval q[ package Oscalar; use overload ('++' => sub { $ {$_[0]}++;$_[0] } ) ]; $b=$a; @@ -118,7 +118,7 @@ test ( $b eq "88"); # 30 test (ref $a eq "Oscalar"); # 31 -$Oscalar::OVERLOAD{'++'} = sub {${$_[0]}+=2;$_[0]}; +eval q[package Oscalar; use overload ('++' => sub { $ {$_[0]} += 2; $_[0] } ) ]; $b=$a; @@ -153,7 +153,10 @@ test (ref $a eq "Oscalar"); # 44 test ($b? 1:0); # 45 -$Oscalar::OVERLOAD{'='} = sub {$copies++; package Oscalar; local $new=${$_[0]};bless \$new}; +eval q[ package Oscalar; use overload ('=' => sub {$main::copies++; + package Oscalar; + local $new=$ {$_[0]}; + bless \$new } ) ]; $b=new Oscalar "$a"; @@ -196,7 +199,8 @@ test ( $b eq "89"); # 67 test (ref $a eq "Oscalar"); # 68 test ($copies == 1); # 69 -$Oscalar::OVERLOAD{'+='} = sub {${$_[0]}+=3*$_[1];$_[0]}; +eval q[package Oscalar; use overload ('+=' => sub {$ {$_[0]} += 3*$_[1]; + $_[0] } ) ]; $c=new Oscalar; # Cause rehash $b=$a; @@ -231,15 +235,18 @@ test (ref $b eq "Oscalar"); # 84 test ( $b eq "360"); # 85 test ($copies == 2); # 86 -$Oscalar::OVERLOAD{'x'} = sub {new Oscalar ($_[2]? "_.$_[1]._" x ${$_[0]}: - "_.${$_[0]}._" x $_[1])}; +eval q[package Oscalar; + use overload ('x' => sub {new Oscalar ( $_[2] ? "_.$_[1]._" x $ {$_[0]} + : "_.${$_[0]}._" x $_[1])}) ]; $a=new Oscalar "yy"; $a x= 3; test ($a eq "_.yy.__.yy.__.yy._"); # 87 -$Oscalar::OVERLOAD{'.'} = sub {new Oscalar ($_[2]? "_.$_[1].__.${$_[0]}._": - "_.${$_[0]}.__.$_[1]._")}; +eval q[package Oscalar; + use overload ('.' => sub {new Oscalar ( $_[2] ? + "_.$_[1].__.$ {$_[0]}._" + : "_.$ {$_[0]}.__.$_[1]._")}) ]; $a=new Oscalar "xx"; @@ -247,13 +254,14 @@ test ("b${a}c" eq "_._.b.__.xx._.__.c._"); # 88 # Here we test blessing to a package updates hash -delete $Oscalar::OVERLOAD{'.'}; +eval "package Oscalar; no overload '.'"; test ("b${a}" eq "_.b.__.xx._"); # 89 $x="1"; bless \$x, Oscalar; -test ("b${a}c" eq "bxxc"); # 90 +test ("b${a}c" eq "bxxc"); # 90 new Oscalar 1; -test ("b${a}c" eq "bxxc"); # 91 +test ("b${a}c" eq "bxxc"); # 91 -sub last {91} +# Last test is number 90. +sub last {90} |