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

Re: Allowing require to return false

Thread Previous | Thread Next
From:
demerphq
Date:
July 27, 2018 14:26
Subject:
Re: Allowing require to return false
Message ID:
CANgJU+UcT78sqeJij0wPg+74Et9wpXVobYLoXGjywPZtvhS5xg@mail.gmail.com
On Thu, 26 Jul 2018 at 21:54, David Nicol <davidnicol@gmail.com> wrote:
>
>
> I may be the only one, but I use this feature.
>
> My modules often end, not with a "1;" which defeats the feature, but with an invocation of an initialization routine which can stop the whole show by returning false.
>
> Am I alone in this?

No. Although it is not a widely used feature.

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.

So there is actually a design objective with this little used feature.
Whether it makes sense as a whole is another discussion.

Yves

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