In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/0b077c88df88ab0d1e7e4c9d8a5a6992563912e1?hp=89e5a02142a942dab03bc79cac055f99a7212ed7>

- Log -----------------------------------------------------------------
commit 0b077c88df88ab0d1e7e4c9d8a5a6992563912e1
Author: Dagfinn Ilmari MannsÃ¥ker <[email protected]>
Date:   Sun Nov 13 15:10:38 2016 +0100

    Improve error for missing tie() pacakge/method
    
    This brings the error messages in line with the ones used for normal
    method calls, despite not using call_method().
-----------------------------------------------------------------------

Summary of changes:
 pp_sys.c   | 21 +++++++++++++++++----
 t/op/tie.t | 12 +++++++++++-
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/pp_sys.c b/pp_sys.c
index b7e5f61..1e1b459 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 cbae110..e5e7d30 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

--
Perl5 Master Repository

Reply via email to