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

Re: Allowing require to return false

Thread Previous | Thread Next
From:
demerphq
Date:
July 28, 2018 08:53
Subject:
Re: Allowing require to return false
Message ID:
CANgJU+Va+Mp30Y9G5xMeUcUgn8qSohy10iPKT_uWeG67fBZy2A@mail.gmail.com
On Fri, 27 Jul 2018 at 22:45, David Nicol <davidnicol@gmail.com> wrote:
>
>
>
> On Fri, Jul 27, 2018 at 2:52 PM demerphq <demerphq@gmail.com> wrote:
>>
>> >
>> > if we have no entry in INC for package
>> > find the file
>> > set INC
>> > do the file
>> > if we die, overwrite the INC entry with undef
>> > if we retiurn false, remove the INC entry
>> > if we return true, leave the INC entry
>
>
>
>>
>> > >
>> > > Note that the file will not be included twice under the same specified name.
>> >
>> > Yes, that is wrong.  If require returns false it can be included again.
>
>
> a defined false, that is, '' or 0. or !1 to be clear.
>
> This is far too long for a seriously proposed rewrite of that line:
>
> Note that the file will not be included twice under the same specified name, unless it compiled and ran and returned a defined but false value, such as C<!1>, in which case it can be loaded again by this mechanism, which might useful for providing an interface where, for instance, a long-running system accepts input and instructions in the form of files of well formed perl code which are copied to a place in the file system. There is more than one way to do it.
>
> INTERPRETATION OF VALUE RETURNED BY REQURIED CODE:
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + CODE IN FILE DOES WHAT     + REQUIRE DOES WHAT                  + WILL RELOAD FILE IF REQUIRED AGAIN? +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + FILE DOES NOT EXIST        + dies "Can't locate"                +             YES                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + FAILS TO COMPILE           + dies "Compilation failed"          +              NO                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + DIES                       + dies "Compilation failed"          +              NO                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + RETURNS UNDEF              + dies "Did not return a true value" +              NO                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + RETURNS DEFINED BUT FALSE  + dies "Did not return a true value" +             YES                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> + RETURNS TRUE               + passes truthy value out            +              NO                     +
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Maybe the third column should be reworked to show what happens on
second load, not simply whether code is executed. For instance, a
second require of a module that died previously will be "Attempt to
reload X failed". Which can be a surprising result if the first load
is in an eval which hides the error, and the second then produces
nothing actionable in terms of a message.

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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