From: Nicholas Clark Date: Mon, 14 Jun 2010 07:44:49 +0000 (+0200) Subject: Note why pp_tie can't use call_method() for a package name. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=086d291379a28ceb3cd7cc6416747be8c426476b;p=p5sagit%2Fp5-mst-13.2.git Note why pp_tie can't use call_method() for a package name. Plus a test that would fail if it did. --- diff --git a/pp_sys.c b/pp_sys.c index 1dadea8..a6d356e 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -855,8 +855,10 @@ PP(pp_tie) call_method(methname, G_SCALAR); } else { - /* Not clear why we don't call call_method here too. - * perhaps to get different error message ? + /* Can't use call_method here, else this: fileno FOO; tie @a, "FOO" + * will attempt to invoke IO::File::TIEARRAY, with (best case) the + * wrong error message, and worse case, supreme action at a distance. + * (Sorry obfuscation writers. You're not going to be given this one.) */ STRLEN len; const char *name = SvPV_nomg_const(*MARK, len); diff --git a/t/op/tie.t b/t/op/tie.t index 38c5cff..5628694 100644 --- a/t/op/tie.t +++ b/t/op/tie.t @@ -929,3 +929,11 @@ print "fetch=$fetch\ncalled=$called\n"; EXPECT fetch=2 called=2 +######## +# tie mustn't attempt to call methods on bareword filehandles. +sub IO::File::TIEARRAY { + die "Did not want to invoke IO::File::TIEARRAY"; +} +fileno FOO; tie @a, "FOO" +EXPECT +Can't locate object method "TIEARRAY" via package "FOO" at - line 5.