From: Gurusamy Sarathy Date: Tue, 4 Jul 2000 16:28:40 +0000 (+0000) Subject: better diagnostic on Frob->stuff() when Frob:: doesn't exist X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1899e02bd58ea340a8d89dc821ccba4502a63a7;p=p5sagit%2Fp5-mst-13.2.git better diagnostic on Frob->stuff() when Frob:: doesn't exist (from Richard Soderberg ) p4raw-id: //depot/perl@6306 --- diff --git a/pod/perldelta.pod b/pod/perldelta.pod index ff4f91f..2a4ad88 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -24,6 +24,16 @@ This document describes differences between the 5.6 release and this one. =head1 New or Changed Diagnostics +=over 4 + +=item (perhaps you forgot to load "%s"?) + +(F) This is an educated guess made in conjunction with the message +"Can't locate object method \"%s\" via package \"%s\"". It often means +that a method requires a package that has not been loaded. + +=back + =head1 New tests =head1 Incompatible Changes diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 800ca4d..c918d41 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -747,6 +747,12 @@ the file, say, by doing C. functioning as a class, but that package doesn't define that particular method, nor does any of its base classes. See L. +=item (perhaps you forgot to load "%s"?) + +(F) This is an educated guess made in conjunction with the message +"Can't locate object method \"%s\" via package \"%s\"". It often means +that a method requires a package that has not been loaded. + =item Can't locate package %s for @%s::ISA (W syntax) The @ISA array contained the name of another package that diff --git a/pp_hot.c b/pp_hot.c index b066b21..2775003 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2884,6 +2884,7 @@ S_method_common(pTHX_ SV* meth, U32* hashp) char* leaf = name; char* sep = Nullch; char* p; + GV* gv; for (p = name; *p; p++) { if (*p == '\'') @@ -2899,9 +2900,18 @@ S_method_common(pTHX_ SV* meth, U32* hashp) packname = name; packlen = sep - name; } - Perl_croak(aTHX_ - "Can't locate object method \"%s\" via package \"%s\"", - leaf, packname); + gv = gv_fetchpv(packname, 0, SVt_PVHV); + if (gv && isGV(gv)) { + Perl_croak(aTHX_ + "Can't locate object method \"%s\" via package \"%s\"", + leaf, packname); + } + else { + Perl_croak(aTHX_ + "Can't locate object method \"%s\" via package \"%s\" + " (perhaps you forgot to load \"%s\"?)", + leaf, packname, packname); + } } return isGV(gv) ? (SV*)GvCV(gv) : (SV*)gv; } diff --git a/t/op/method.t b/t/op/method.t index 1c6f3c5..d2f1300 100755 --- a/t/op/method.t +++ b/t/op/method.t @@ -4,7 +4,7 @@ # test method calls and autoloading. # -print "1..49\n"; +print "1..53\n"; @A::ISA = 'B'; @B::ISA = 'C'; @@ -167,3 +167,16 @@ test(defined(@{"unknown_package::ISA"}) ? "defined" : "undefined", "undefined"); test(do { eval 'A2::foo()'; $@ ? 1 : 0}, 1); test(A2->foo(), "foo"); } + +{ + test(do { use Config; eval 'Config->foo()'; + $@ =~ /^\QCan't locate object method "foo" via package "Config" at/ ? 1 : $@}, 1); + test(do { use Config; eval '$d = bless {}, "Config"; $d->foo()'; + $@ =~ /^\QCan't locate object method "foo" via package "Config" at/ ? 1 : $@}, 1); +} + +test(do { eval 'E->foo()'; + $@ =~ /^\QCan't locate object method "foo" via package "E" (perhaps / ? 1 : $@}, 1); +test(do { eval '$e = bless {}, "E"; $e->foo()'; + $@ =~ /^\QCan't locate object method "foo" via package "E" (perhaps / ? 1 : $@}, 1); +