This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Patch to show @INC when require dies
authorJim Avera <avera@hal.com>
Thu, 22 May 1997 06:10:01 +0000 (18:10 +1200)
committerTim Bunce <Tim.Bunce@ig.co.uk>
Wed, 11 Jun 1997 00:00:00 +0000 (12:00 +1200)
When 'require' dies because it can't find the file in @INC, it would
be helpful if perl printed out the contents of @INC, to help debu
the problem (especially when perl is invoked in devious ways, such
as via a C application in which perl is embedded with funny secret
-I args passed to perl_parse!).

I would like to contribute a patch to 5.004 to do just that.

p5p-msgid: 9705230121.AA27872@membrane.hal.com

pp_ctl.c

index bc3ebb1..6052cb2 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2306,10 +2306,20 @@ PP(pp_require)
     if (!tryrsfp) {
        if (op->op_type == OP_REQUIRE) {
            SV *msg = sv_2mortal(newSVpvf("Can't locate %s in @INC", name));
+           SV *dirmsgsv = NEWSV(0, 0);
+           AV *ar = GvAVn(incgv);
+           I32 i;
            if (instr(SvPVX(msg), ".h "))
                sv_catpv(msg, " (change .h to .ph maybe?)");
            if (instr(SvPVX(msg), ".ph "))
                sv_catpv(msg, " (did you run h2ph?)");
+           sv_catpv(msg, "\n@INC contains:\n ");
+           for (i = 0; i <= AvFILL(ar); i++) {
+               char *dir = SvPVx(*av_fetch(ar, i, TRUE), na);
+               sv_setpvf(dirmsgsv, "   %s\n ", dir);
+               sv_catsv(msg, dirmsgsv);
+           }
+           SvREFCNT_dec(dirmsgsv);
            DIE("%_", msg);
        }