summaryrefslogtreecommitdiff
path: root/lib/overload.t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-04-25 17:43:50 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-04-25 17:43:50 +0000
commit41cb10058d4b3aa9d11d3b8991811c08c7fcc328 (patch)
treedc6ff763f1db7202ae4a08602e88692a40276b58 /lib/overload.t
parent3a7016a88d877abd83ec249112ec5d7c6c2c696b (diff)
downloadperl-41cb10058d4b3aa9d11d3b8991811c08c7fcc328.tar.gz
More %{} overload tests.
p4raw-id: //depot/perl@16163
Diffstat (limited to 'lib/overload.t')
-rw-r--r--lib/overload.t20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t
index cf49eac45a..4db647dbee 100644
--- a/lib/overload.t
+++ b/lib/overload.t
@@ -1066,5 +1066,23 @@ package main;
my $utfvar = new utf8_o 200.2.1;
test("$utfvar" eq 200.2.1); # 223
+# 224..226 -- more %{} tests. Hangs in 5.6.0, okay in later releases.
+# Basically this example implements strong encapsulation: if Hderef::import()
+# were to eval the overload code in the caller's namespace, the privatisation
+# would be quite transparent.
+package Hderef;
+use overload '%{}' => sub { (caller(0))[0] eq 'Foo' ? $_[0] : die "zap" };
+package Foo;
+@Foo::ISA = 'Hderef';
+sub new { bless {}, shift }
+sub xet { @_ == 2 ? $_[0]->{$_[1]} :
+ @_ == 3 ? ($_[0]->{$_[1]} = $_[2]) : undef }
+package main;
+my $a = Foo->new;
+$a->xet('b', 42);
+print $a->xet('b') == 42 ? "ok 224\n" : "not ok 224\n";
+print defined eval { $a->{b} } ? "not ok 225\n" : "ok 225\n";
+print $@ =~ /zap/ ? "ok 226\n" : "not ok 226\n";
+
# Last test is:
-sub last {223}
+sub last {226}