emit more appropriate diagnostic for failed glob (variant
[p5sagit/p5-mst-13.2.git] / pp_hot.c
index f48e98f..7709c53 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -204,19 +204,15 @@ PP(pp_readline)
 {
     tryAMAGICunTARGET(iter, 0);
     PL_last_in_gv = (GV*)(*PL_stack_sp--);
-    if (PL_op->op_flags & OPf_SPECIAL) {       /* Are called as <$var> */
-       if (SvROK(PL_last_in_gv)) {
-           if (SvTYPE(SvRV(PL_last_in_gv)) != SVt_PVGV) 
-               goto hard_way;
+    if (SvTYPE(PL_last_in_gv) != SVt_PVGV) {
+       if (SvROK(PL_last_in_gv) && SvTYPE(SvRV(PL_last_in_gv)) == SVt_PVGV) 
            PL_last_in_gv = (GV*)SvRV(PL_last_in_gv);
-       } else if (SvTYPE(PL_last_in_gv) != SVt_PVGV) {
-         hard_way: {
+       else {
            dSP;
            XPUSHs((SV*)PL_last_in_gv);
            PUTBACK;
            pp_rv2gv(ARGS);
            PL_last_in_gv = (GV*)(*PL_stack_sp--);
-         }
        }
     }
     return do_readline();
@@ -237,7 +233,7 @@ PP(pp_preinc)
     djSP;
     if (SvREADONLY(TOPs) || SvTYPE(TOPs) > SVt_PVLV)
        croak(PL_no_modify);
-    if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) &&
+    if (SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs) &&
        SvIVX(TOPs) != IV_MAX)
     {
        ++SvIVX(TOPs);
@@ -1236,9 +1232,15 @@ do_readline(void)
                sv_setpv(tmpcmd, "/dev/dosglob/"); /* File System Extension */
                sv_catsv(tmpcmd, tmpglob);
 #else
+#ifdef CYGWIN32
+               sv_setpv(tmpcmd, "for a in ");
+               sv_catsv(tmpcmd, tmpglob);
+               sv_catpv(tmpcmd, "; do echo -e \"$a\\0\\c\"; done |");
+#else
                sv_setpv(tmpcmd, "perlglob ");
                sv_catsv(tmpcmd, tmpglob);
                sv_catpv(tmpcmd, " |");
+#endif /* !CYGWIN */
 #endif /* !DJGPP */
 #endif /* !OS2 */
 #else /* !DOSISH */
@@ -1268,9 +1270,14 @@ do_readline(void)
            SP--;
     }
     if (!fp) {
-       if (ckWARN(WARN_CLOSED) && io && !(IoFLAGS(io) & IOf_START))
-           warner(WARN_CLOSED,
-                  "Read on closed filehandle <%s>", GvENAME(PL_last_in_gv));
+       if (ckWARN(WARN_CLOSED) && io && !(IoFLAGS(io) & IOf_START)) {
+           if (type == OP_GLOB)
+               warner(WARN_CLOSED, "glob failed (can't start child: %s)",
+                      Strerror(errno));
+           else
+               warner(WARN_CLOSED, "Read on closed filehandle <%s>",
+                      GvENAME(PL_last_in_gv));
+       }
        if (gimme == G_SCALAR) {
            (void)SvOK_off(TARG);
            PUSHTARG;
@@ -2092,10 +2099,13 @@ PP(pp_entersub)
        break;
     case SVt_PVGV:
        if (!(cv = GvCVu((GV*)sv)))
-           cv = sv_2cv(sv, &stash, &gv, TRUE);
-       if (cv)
-           break;
-       DIE("Not a CODE reference");
+           cv = sv_2cv(sv, &stash, &gv, FALSE);
+       if (!cv) {
+           ENTER;
+           SAVETMPS;
+           goto try_autoload;
+       }
+       break;
     }
 
     ENTER;
@@ -2115,16 +2125,19 @@ PP(pp_entersub)
            cv = GvCV(gv);
        }
        /* should call AUTOLOAD now? */
-       else if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
-                                  FALSE)))
-       {
-           cv = GvCV(autogv);
-       }
-       /* sorry */
        else {
-           sub_name = sv_newmortal();
-           gv_efullname3(sub_name, gv, Nullch);
-           DIE("Undefined subroutine &%s called", SvPVX(sub_name));
+try_autoload:
+           if ((autogv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv),
+                                  FALSE)))
+           {
+               cv = GvCV(autogv);
+           }
+           /* sorry */
+           else {
+               sub_name = sv_newmortal();
+               gv_efullname3(sub_name, gv, Nullch);
+               DIE("Undefined subroutine &%s called", SvPVX(sub_name));
+           }
        }
        if (!cv)
            DIE("Not a CODE reference");