summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_sys.c21
-rw-r--r--t/op/tie.t12
2 files changed, 28 insertions, 5 deletions
diff --git a/pp_sys.c b/pp_sys.c
index b7e5f61cf8..1e1b459a1a 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -952,10 +952,23 @@ PP(pp_tie)
* (Sorry obfuscation writers. You're not going to be given this one.)
*/
stash = gv_stashsv(*MARK, 0);
- if (!stash || !(gv = gv_fetchmethod(stash, methname))) {
- DIE(aTHX_ "Can't locate object method \"%s\" via package \"%"SVf"\"",
- methname, SVfARG(SvOK(*MARK) ? *MARK : &PL_sv_no));
- }
+ if (!stash) {
+ SV *stashname = SvOK(*MARK) ? *MARK : &PL_sv_no;
+ if (!SvCUR(*MARK)) {
+ stashname = sv_2mortal(newSVpvs("main"));
+ }
+ DIE(aTHX_ "Can't locate object method \"%s\" via package \"%"SVf"\""
+ " (perhaps you forgot to load \"%"SVf"\"?)",
+ methname, SVfARG(stashname), SVfARG(stashname));
+ }
+ else if (!(gv = gv_fetchmethod(stash, methname))) {
+ /* The effective name can only be NULL for stashes that have
+ * been deleted from the symbol table, which this one can't
+ * be, since we just looked it up by name.
+ */
+ DIE(aTHX_ "Can't locate object method \"%s\" via package \"%"HEKf"\"",
+ methname, HvENAME_HEK_NN(stash));
+ }
ENTER_with_name("call_TIE");
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
diff --git a/t/op/tie.t b/t/op/tie.t
index cbae110b44..e5e7d30cc6 100644
--- a/t/op/tie.t
+++ b/t/op/tie.t
@@ -930,7 +930,17 @@ sub IO::File::TIEARRAY {
}
fileno FOO; tie @a, "FOO"
EXPECT
-Can't locate object method "TIEARRAY" via package "FOO" at - line 5.
+Can't locate object method "TIEARRAY" via package "FOO" (perhaps you forgot to load "FOO"?) at - line 5.
+########
+# tie into empty package name
+tie $foo, "";
+EXPECT
+Can't locate object method "TIESCALAR" via package "main" at - line 2.
+########
+# tie into undef package name
+tie $foo, undef;
+EXPECT
+Can't locate object method "TIESCALAR" via package "main" at - line 2.
########
#
# STORE freeing tie'd AV