summaryrefslogtreecommitdiff
path: root/lib/overload.t
diff options
context:
space:
mode:
authorRick Delaney <rick@consumercontact.com>2007-10-06 20:22:14 -0400
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-10-07 09:44:22 +0000
commitc781a409e12d3d0d5a289d2e43b9c4e399d30667 (patch)
tree353c258a9626a807e6eddff5de97df32ce6850b8 /lib/overload.t
parent88c9ea1eee075fb55dd1fa8e866125da26b560ff (diff)
downloadperl-c781a409e12d3d0d5a289d2e43b9c4e399d30667.tar.gz
Re: [perl #46011] overload "0+" doesn't handle integer results
Message-ID: <20071007042214.GH29047@bort.ca> p4raw-id: //depot/perl@32059
Diffstat (limited to 'lib/overload.t')
-rw-r--r--lib/overload.t27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t
index 34b4521db5..9b1792328b 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 => 528;
+use Test::More tests => 535;
$a = new Oscalar "087";
@@ -1375,3 +1375,28 @@ foreach my $op (qw(<=> == != < <= > >=)) {
is("$wham_eth", $string);
is ($crunch_eth->Pie("Blackbird"), "$string, Blackbird");
}
+
+{
+ package numify_int;
+ use overload "0+" => sub { $_[0][0] += 1; 42 };
+ package numify_self;
+ use overload "0+" => sub { $_[0][0]++; $_[0] };
+ package numify_other;
+ use overload "0+" => sub { $_[0][0]++; $_[0][1] = bless [], 'numify_int' };
+
+ package main;
+ my $o = bless [], 'numify_int';
+ is(int($o), 42, 'numifies to integer');
+ is($o->[0], 1, 'int() numifies only once');
+
+ my $aref = [];
+ my $num_val = 0 + $aref;
+ my $r = bless $aref, 'numify_self';
+ is(int($r), $num_val, 'numifies to self');
+ is($r->[0], 1, 'int() numifies once when returning self');
+
+ my $s = bless [], 'numify_other';
+ is(int($s), 42, 'numifies to numification of other object');
+ is($s->[0], 1, 'int() numifies once when returning other object');
+ is($s->[1][0], 1, 'returned object numifies too');
+}