summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2017-03-07 14:50:11 +1100
committerTony Cook <tony@develop-help.com>2017-03-14 21:57:18 +1100
commit2a0461a3212270dfe46563589edb8c721911bf57 (patch)
treee2d16645b8a16a2175dc553b09c902262e97ff28
parent12e837793e279bd6e705e920b9492f60dee90dfe (diff)
downloadperl-2a0461a3212270dfe46563589edb8c721911bf57.tar.gz
warn if do "somefile" fails when . not default in @INC and somefile exists
the message and warning category may need adjustment
-rw-r--r--pod/perldiag.pod8
-rw-r--r--pp_ctl.c27
-rw-r--r--t/lib/warnings/pp_ctl13
3 files changed, 44 insertions, 4 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 390ba81e09..9a4cdf6352 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2061,6 +2061,14 @@ define a C<$VERSION>.
(F) You cannot put a repeat count of any kind right after the '/' code.
See L<perlfunc/pack>.
+=item do "%s" failed, '.' is no longer in @INC
+
+(W deprecated) Previously C< do "somefile"; > would search the current
+directory for the specified file. Since F<.> has been removed from
+C<@INC> by default this is no longer true. To search the current
+directory (and only the current directory) you can write C< do
+"./somefile"; >.
+
=item Don't know how to get file name
(P) C<PerlIO_getname>, a perl internal I/O function specific to VMS, was
diff --git a/pp_ctl.c b/pp_ctl.c
index ef5b122824..a1262323e5 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3695,7 +3695,7 @@ S_require_version(pTHX_ SV *sv)
* the second form */
static OP *
-S_require_file(pTHX_ SV *const sv)
+S_require_file(pTHX_ SV *sv)
{
dVAR; dSP;
@@ -4104,9 +4104,28 @@ S_require_file(pTHX_ SV *const sv)
}
DIE(aTHX_ "Can't locate %s", name);
}
-
- CLEAR_ERRSV();
- RETPUSHUNDEF;
+ else {
+#ifdef DEFAULT_INC_EXCLUDES_DOT
+ Stat_t st;
+ PerlIO *io = NULL;
+ dSAVE_ERRNO;
+ /* the complication is to match the logic from doopen_pm() so we don't treat do "sda1" as
+ a previously successful "do".
+ */
+ bool do_warn = namesv && ckWARN_d(WARN_DEPRECATED)
+ && PerlLIO_stat(name, &st) == 0 && !S_ISDIR(st.st_mode) && !S_ISBLK(st.st_mode)
+ && (io = PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &sv)) != NULL;
+ if (io)
+ PerlIO_close(io);
+
+ RESTORE_ERRNO;
+ if (do_warn) {
+ Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "do \"%s\" failed, '.' is no longer in @INC", name);
+ }
+#endif
+ CLEAR_ERRSV();
+ RETPUSHUNDEF;
+ }
}
else
SETERRNO(0, SS_NORMAL);
diff --git a/t/lib/warnings/pp_ctl b/t/lib/warnings/pp_ctl
index 9b3f2982e4..27efbcbda5 100644
--- a/t/lib/warnings/pp_ctl
+++ b/t/lib/warnings/pp_ctl
@@ -251,3 +251,16 @@ EXPECT
use warnings;
eval 'use 5.006; use 5.10.0';
EXPECT
+########
+# SKIP ? !$Config{default_inc_includes_dot}
+# NAME check warning for do with no . in @INC
+open my $fh, ">", "dounknown";
+close $fh;
+do "dounknown";
+do "./dounknown";
+no warnings 'deprecated';
+do "dounknown";
+do "./dounknown";
+unlink "dounknown";
+EXPECT
+do "dounknown" failed, '.' is no longer in @INC at - line 3.