summaryrefslogtreecommitdiff
path: root/pp_ctl.c
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 /pp_ctl.c
parent6f76d139d7a6eead1be43e6e20b74edbdac0e8ff (diff)
downloadperl-2c9d2554ad3b3d37d1c8b83cf0f3c4b4b99fde8b.tar.gz
Allow ~~ overloading on the left side, when the right side is a plain scalar
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index e12b6719a6..5adfc686b9 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4001,6 +4001,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
SV *e = TOPs; /* e is for 'expression' */
SV *d = TOPm1s; /* d is for 'default', as in PL_defgv */
+ /* First of all, handle overload magic of the rightmost argument */
if (SvAMAGIC(e)) {
SV * const tmpsv = amagic_call(d, e, smart_amg, 0);
if (tmpsv) {
@@ -4371,9 +4372,25 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other)
RETURN;
}
}
- /* ~~ X..Y TODO */
/* ~~ scalar */
- else if (SvNIOK(e) || (SvPOK(e) && looks_like_number(e) && SvNIOK(d))) {
+ /* See if there is overload magic on left */
+ else if (object_on_left && SvAMAGIC(d)) {
+ SV *tmpsv;
+ PUSHs(d); PUSHs(e);
+ PUTBACK;
+ tmpsv = amagic_call(d, e, smart_amg, AMGf_noright);
+ if (tmpsv) {
+ SPAGAIN;
+ (void)POPs;
+ SETs(tmpsv);
+ RETURN;
+ }
+ SP -= 2;
+ goto sm_any_scalar;
+ }
+ else
+ sm_any_scalar:
+ if (SvNIOK(e) || (SvPOK(e) && looks_like_number(e) && SvNIOK(d))) {
/* numeric comparison */
PUSHs(d); PUSHs(e);
PUTBACK;