summaryrefslogtreecommitdiff
path: root/lib/overload.t
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-03-15 15:08:49 +0000
committerNicholas Clark <nick@ccl4.org>2006-03-15 15:08:49 +0000
commitdd2eae666980a8d8bd145f2f6cc632a45513f9ce (patch)
tree673f08c186f18bc96c78a7e03ff697591094b1d6 /lib/overload.t
parentb1fbf5c3d1dc6dd7934002da04dede2ae2e3ef65 (diff)
downloadperl-dd2eae666980a8d8bd145f2f6cc632a45513f9ce.tar.gz
Moving the overloading flag from the reference to the referant allows
(re)?blessing of overloaded objects to work correctly. p4raw-id: //depot/perl@27506
Diffstat (limited to 'lib/overload.t')
-rw-r--r--lib/overload.t47
1 files changed, 46 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t
index 78548605f3..cf553ceb86 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=>497;
+use Test::More tests=>503;
$a = new Oscalar "087";
@@ -1180,3 +1180,48 @@ foreach my $op (qw(<=> == != < <= > >=)) {
BEGIN { overload::constant integer => sub { 23 } }
is(eval "17", $twenty_three);
}
+
+{
+ package Sklorsh;
+ use overload
+ bool => sub { shift->is_cool };
+
+ sub is_cool {
+ $_[0]->{name} eq 'cool';
+ }
+
+ sub delete {
+ undef %{$_[0]};
+ bless $_[0], 'Brap';
+ return 1;
+ }
+
+ sub delete_with_self {
+ my $self = shift;
+ undef %$self;
+ bless $self, 'Brap';
+ return 1;
+ }
+
+ package Brap;
+
+ 1;
+
+ package main;
+
+ my $obj;
+ $obj = bless {name => 'cool'}, 'Sklorsh';
+ $obj->delete;
+ ok(eval {if ($obj) {1}; 1}, $@ || 'reblessed into nonexist namespace');
+
+ $obj = bless {name => 'cool'}, 'Sklorsh';
+ $obj->delete_with_self;
+ ok (eval {if ($obj) {1}; 1}, $@);
+
+ my $a = $b = {name => 'hot'};
+ bless $b, 'Sklorsh';
+ is(ref $a, 'Sklorsh');
+ is(ref $b, 'Sklorsh');
+ ok(!$b, "Expect overloaded boolean");
+ ok(!$a, "Expect overloaded boolean");
+}