summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-24 23:51:42 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-05-24 23:51:42 +0200
commit2c9d2554ad3b3d37d1c8b83cf0f3c4b4b99fde8b (patch)
tree478055ef6f793001bacf3869e457460532da243b /t
parent6f76d139d7a6eead1be43e6e20b74edbdac0e8ff (diff)
downloadperl-2c9d2554ad3b3d37d1c8b83cf0f3c4b4b99fde8b.tar.gz
Allow ~~ overloading on the left side, when the right side is a plain scalar
Diffstat (limited to 't')
-rw-r--r--t/op/smartmatch.t20
1 files changed, 15 insertions, 5 deletions
diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t
index 5dfebbd842..8c487688a1 100644
--- a/t/op/smartmatch.t
+++ b/t/op/smartmatch.t
@@ -37,7 +37,15 @@ tie my %tied_hash, 'Tie::StdHash';
{
package Test::Object::WithOverload;
sub new { bless { key => 'magic' } }
- use overload '~~' => sub { my %hash = %{ $_[0] }; $_[1] eq $hash{key} };
+ use overload '~~' => sub {
+ my %hash = %{ $_[0] };
+ if ($_[2]) { # arguments reversed ?
+ return $_[1] eq reverse $hash{key};
+ }
+ else {
+ return $_[1] eq $hash{key};
+ }
+ };
use overload '""' => sub { "stringified" };
use overload 'eq' => sub {"$_[0]" eq "$_[1]"};
}
@@ -158,15 +166,15 @@ __DATA__
# Any ~~ object overloaded
! \&fatal $ov_obj
- 'magic' $ov_obj
-! 'not magic' $ov_obj
+ 'cigam' $ov_obj
+! 'cigam on' $ov_obj
! $obj $ov_obj
! undef $ov_obj
# regular object
@ $obj $obj
@ $ov_obj $obj
-@ \&fatal $obj
+=@ \&fatal $obj
@ \&FALSE $obj
@ \&foo $obj
@ sub { 1 } $obj
@@ -183,7 +191,9 @@ __DATA__
# object (overloaded or not) ~~ Any
$obj qr/NoOverload/
$ov_obj qr/^stringified$/
- $ov_obj "stringified"
+ "$ov_obj" "stringified"
+ $ov_obj 'magic'
+! $ov_obj 'not magic'
# ~~ Coderef
sub{0} sub { ref $_[0] eq "CODE" }