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

Re: Allowing require to return false

Thread Previous | Thread Next
David Nicol
July 27, 2018 19:13
Re: Allowing require to return false
Message ID:
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 <> (exists
   <> $INC{$filename}) {
   2. return <> 1 if
   <> $INC{$filename};
   3. croak "Compilation failed in require";
   4. }


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 <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About