develooper Front page | perl.perl5.porters | Postings from March 2017

Re: The tricky issue of do()

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 31, 2017 08:27
Subject:
Re: The tricky issue of do()
Message ID:
20170331082653.GA29009@iabyn.com
On Thu, Mar 30, 2017 at 10:26:05PM +0000, Matt S Trout wrote:
> On Thu, Mar 30, 2017 at 08:26:49AM +0100, Dave Mitchell wrote:
> > Well, the first example within the '=item do EXPR' section is
> > 
> >     do './stat.pl';
> > 
> > Is that what you meant?
> 
> Ok, that's already fixed then, cool.
>  
> > > and instead of just
> > > 
> > >   do "stat.pl" failed, '.' is no longer in @INC
> > > 
> > > the warning should be
> > > 
> > >   do "stat.pl" failed, '.' is no longer in @INC, did you mean do "./stat.pl" ?
> > > 
> > > ala the "did you need to install" error on require() failure.
> > 
> > I'd be reluctant to change the warning at this extremely late stage.
> 
> Well, the entire point of the warning was that this is most likely to affect
> newbies or baby perl authors who don't understand what's going on and so
> need hand holding through updating their code to match.
> 
> That's what this thread was about, basically - and the current warning is
> barely more useful than nothing at all for that purposes.
> 
> As such, I'd be reluctant to ship without making the warning actually useful,
> otherwise why did we bother adding it at all?

I've now pushed the following:

commit 1c99110e81e1b5fb8dad0a368bf6aa2f3439cc22
Author:     David Mitchell <davem@iabyn.com>
AuthorDate: Fri Mar 31 09:13:33 2017 +0100
Commit:     David Mitchell <davem@iabyn.com>
CommitDate: Fri Mar 31 09:13:33 2017 +0100

    tweak 'do "%s" failed' message
    
    The warning
    
        do "%s" failed, '.' is no longer in @INC
    
    was added in  the previous devel release; this commit enhances it to say
    
        do "%s" failed, '.' is no longer in @INC; did you mean do "./%s"
    
    and updates the relevant docs.
    
    See http://nntp.perl.org/group/perl.perl5.porters/243788.


Affected files ...
    M	pod/perl52511delta.pod
    M	pod/perldiag.pod
    M	pod/perlfunc.pod
    M	pp_ctl.c
    M	t/lib/warnings/pp_ctl

Differences ...

diff --git a/pod/perl52511delta.pod b/pod/perl52511delta.pod
index 5deac54..e758c01 100644
--- a/pod/perl52511delta.pod
+++ b/pod/perl52511delta.pod
@@ -97,10 +97,11 @@ L<VMS::Stdio> has been upgraded from version 2.42 to 2.41.
 
 =item *
 
-Since C<.> is removed from C<@INC>, C<do> will now trigger a warning
-recommending on fixing the C<do> statement.
+Since C<.> is now removed from C<@INC> by default, C<do> will now trigger
+a warning recommending to fix the C<do> statement:
 
-L<do "%s" failed, '.' is no longer in @INC|perldiag/"do "%s" failed, '.' is no longer in @INC">
+L<do "%s" failed, '.' is no longer in @INC|perldiag/"do "%s" failed, '.'
+is no longer in @INC; did you mean do "./%s"?>
 
 =back
 
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 9a4cdf6..97399c7 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2061,13 +2061,13 @@ 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
+=item do "%s" failed, '.' is no longer in @INC; did you mean do "./%s"?
 
 (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"; >.
+directory for the specified file.  Since perl v5.26.0, F<.> has been
+removed from C<@INC> by default, so 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
 
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index ae97bce..357cd21 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -1829,8 +1829,11 @@ L<C<%INC>|perlvar/%INC> if the file is found.  See L<perlvar/@INC>
 and L<perlvar/%INC> for these variables. In particular, note that
 whilst historically L<C<@INC>|perlvar/@INC> contained '.' (the
 current directory) making these two cases equivalent, that is no
-longer necessarily the case, as there is now a compile-time option
-to disable this behaviour.
+longer necessarily the case, as '.' is not included in C<@INC> by default
+in perl versions 5.26.0 onwards. Instead, perl will now warn:
+
+    do "stat.pl" failed, '.' is no longer in @INC;
+    did you mean do "./stat.pl"?
 
 If L<C<do>|/do EXPR> can read the file but cannot compile it, it
 returns L<C<undef>|/undef EXPR> and sets an error message in
diff --git a/pp_ctl.c b/pp_ctl.c
index a126232..3ad4c65 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4120,7 +4120,10 @@ S_require_file(pTHX_ SV *sv)
 
             RESTORE_ERRNO;
             if (do_warn) {
-                Perl_warner(aTHX_ packWARN(WARN_DEPRECATED), "do \"%s\" failed, '.' is no longer in @INC", name);
+                Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
+                "do \"%s\" failed, '.' is no longer in @INC; "
+                "did you mean do \"./%s\"?",
+                name, name);
             }
 #endif
             CLEAR_ERRSV();
diff --git a/t/lib/warnings/pp_ctl b/t/lib/warnings/pp_ctl
index 27efbcb..37dd4f1 100644
--- a/t/lib/warnings/pp_ctl
+++ b/t/lib/warnings/pp_ctl
@@ -263,4 +263,4 @@ do "dounknown";
 do "./dounknown";
 unlink "dounknown";
 EXPECT
-do "dounknown" failed, '.' is no longer in @INC at - line 3.
+do "dounknown" failed, '.' is no longer in @INC; did you mean do "./dounknown" at - line 3.


-- 
Counsellor Troi states something other than the blindingly obvious.
    -- Things That Never Happen in "Star Trek" #16

Thread Previous | 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