develooper Front page | perl.perl5.porters | Postings from July 2018

Re: Allowing require to return false

Thread Previous | Thread Next
From:
David Nicol
Date:
July 27, 2018 19:13
Subject:
Re: Allowing require to return false
Message ID:
CAFwScO_vAJ=O0u0O0vrh61s+DxbgUSXUKdLA8UhnbxdwA0EHgw@mail.gmail.com
is this subtle difference checked in the test suite?

As perldoc -f require doesn't describe this subtle difference, and actually
documents a semantic inconsistent with it, with



   1. if <https://perldoc.perl.org/functions/if.html> (exists
   <https://perldoc.perl.org/functions/exists.html> $INC{$filename}) {
   2. return <https://perldoc.perl.org/functions/return.html> 1 if
   <https://perldoc.perl.org/functions/if.html> $INC{$filename};
   3. croak "Compilation failed in require";
   4. }


and

Note that the file will not be included twice under the same specified name.



it seems like a documentation patch would be eminently committable.


On Fri, Jul 27, 2018 at 9:26 AM demerphq <demerphq@gmail.com> wrote:

> Many people are unaware of the subtle difference of returning false
> from a require, and dieing in a require.
>
> When require returns false, a subsequent require will reload and
> compile and execute code a second time.
>
> When require dies, a subsequent require will throw an exception about
> attempting to reload a module.
>
> What this means is that a false return from require can signal to the
> code that called require that it needs to do something and reload the
> file again.
>

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