develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #115048] [PATCH 2/2] Suggest cause of error requiring .pm file.

Thread Next
From:
Paul Johnson
Date:
September 25, 2012 17:45
Subject:
[perl #115048] [PATCH 2/2] Suggest cause of error requiring .pm file.
Message ID:
rt-3.6.HEAD-11172-1348620333-302.115048-75-0@perl.org
# New Ticket Created by  "Paul Johnson" 
# Please include the string:  [perl #115048]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=115048 >


---
 cpan/parent/t/parent.t |    4 ++--
 pp_ctl.c               |   30 ++++++++++++++++++++++--------
 t/op/require_errors.t  |    2 +-
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/cpan/parent/t/parent.t b/cpan/parent/t/parent.t
index 401fe39..b9a70e8 100644
--- a/cpan/parent/t/parent.t
+++ b/cpan/parent/t/parent.t
@@ -58,10 +58,10 @@ is( $Eval2::VERSION, '1.02' );
 
 
 eval q{use parent 'reallyReAlLyNotexists'};
-like( $@, q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(\@INC contains:/}, 'baseclass that does not exist');
+like( $@, q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(have you installed the reallyReAlLyNotexists module\?\) \(\@INC contains:/}, 'baseclass that does not exist');
 
 eval q{use parent 'reallyReAlLyNotexists'};
-like( $@, q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(\@INC contains:/}, '  still failing on 2nd load');
+like( $@, q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(have you installed the reallyReAlLyNotexists module\?\) \(\@INC contains:/}, '  still failing on 2nd load');
 {
     my $warning;
     local $SIG{__WARN__} = sub { $warning = shift };
diff --git a/pp_ctl.c b/pp_ctl.c
index ce88220..751fd65 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3925,22 +3925,36 @@ PP(pp_require)
 	        if (namesv) {			/* did we lookup @INC? */
 		    AV * const ar = GvAVn(PL_incgv);
 		    I32 i;
+		    SV *const msg = newSVpv("", 0);
 		    SV *const inc = newSVpvs_flags("", SVs_TEMP);
 		    for (i = 0; i <= AvFILL(ar); i++) {
 			sv_catpvs(inc, " ");
 			sv_catsv(inc, *av_fetch(ar, i, TRUE));
 		    }
+		    if (len >= 4 && memEQ(name + len - 3, ".pm", 4)) {
+			const char *c, *e = name + len - 3;
+			sv_catpv(msg, " (have you installed the ");
+			for (c = name; c < e; c++) {
+			    if (*c == '/') {
+				sv_catpvn(msg, "::", 2);
+			    }
+			    else {
+				sv_catpvn(msg, c, 1);
+			    }
+			}
+			sv_catpv(msg, " module?)");
+		    }
+		    else if (len >= 2 && memEQ(name + len - 2, ".h", 3)) {
+			sv_catpv(msg, " (change .h to .ph maybe?) (did you run h2ph?)");
+		    }
+		    else if (len >= 3 && memEQ(name + len - 3, ".ph", 4)) {
+			sv_catpv(msg, " (did you run h2ph?)");
+		    }
 
 		    /* diag_listed_as: Can't locate %s */
 		    DIE(aTHX_
-			"Can't locate %s in @INC%s%s (@INC contains:%" SVf ")",
-			name,
-			(len >= 2 && memEQ(name + len - 2, ".h", 3)
-			 ? " (change .h to .ph maybe?) (did you run h2ph?)" : ""),
-			(len >= 3 && memEQ(name + len - 3, ".ph", 4)
-			 ? " (did you run h2ph?)" : ""),
-			inc
-			);
+			"Can't locate %s in @INC%" SVf " (@INC contains:%" SVf ")",
+			name, msg, inc);
 		}
 	    }
 	    DIE(aTHX_ "Can't locate %s", name);
diff --git a/t/op/require_errors.t b/t/op/require_errors.t
index 1f243a6..7211712 100644
--- a/t/op/require_errors.t
+++ b/t/op/require_errors.t
@@ -27,7 +27,7 @@ for my $file ($nonfile, ' ') {
 
 eval "require $nonfile";
 
-like $@, qr/^Can't locate $nonfile\.pm in \@INC \(\@INC contains: @INC\) at/,
+like $@, qr/^Can't locate $nonfile\.pm in \@INC \(have you installed the $nonfile module\?\) \(\@INC contains: @INC\) at/,
     "correct error message for require $nonfile";
 
 eval {
-- 
1.7.9.5


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About