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

Re: The tricky issue of do()

Thread Previous | Thread Next
Dave Mitchell
March 29, 2017 11:38
Re: The tricky issue of do()
Message ID:
On Mon, Feb 27, 2017 at 02:24:54PM +0000, Dominic Hargreaves wrote:
> On Mon, Feb 27, 2017 at 03:07:47PM +0100, Christian Walde wrote:
> > On Mon, 27 Feb 2017 14:56:23 +0100, Sawyer X <> wrote:
> > 
> > >>>The point has been raised by haarg and leont that that might not be
> > >>>entirely straight-forward due to shared code between use/require, but i
> > >>>think in this case backwards compatibiliy should trump, even if the core
> > >>>code looks a little more ugly as a result.
> > >>Although I lean towards the backwards compatility camp, note that we can't
> > >>provide *exact* backcompat even if we wanted to: the old behaviour of do()
> > >>was strictly to search @INC, and @INC just happened often to have '.' as
> > >>its last member.
> > >>
> > >>The most obvious backcompat strategy is to make 'do' always treat @INC as
> > >>having an implicit trailing '.' when loading a 'do' file; but this will
> > >>mean that code which explicitly removed '.' from @INC for security or
> > >>other reasons will suddenly have 'do' loading files from locations it
> > >>previously wouldn't have.
> > >
> > >This is why I believe a warning would be useful here instead.
> > 
> > And correction of the documentation, which was only correct for 99% of cases before, but after '.' removal would be correct for only 1%.
> I merged my doc patch from rt#130832 at the weekend. This should make
> the documentation consistent with current behaviour. Of course, it would
> need a further tweak if warnings were to be added.

Does the following change to the 'do' entry in perlfunc look plausible to
cope withe the facts that:
    * dot is now removed from @INC by default;
    * do now warns;

index ae97bce..565fe3f 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -1829,8 +1829,10 @@ 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 "" failed, '.' is no longer in @INC
 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

Hofstadter's Law: It always takes longer than you expect, even when you
take into account Hofstadter's Law.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About