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 20:45
Subject:
Re: Allowing require to return false
Message ID:
CAFwScO-wiecrgSsxz3D4DRm9HG3fhwb=xZ1NH5aj77U5maj_dQ@mail.gmail.com
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                     +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




> >
> > > it seems like a documentation patch would be eminently committable.
> >
> > Yeah, i guess so. Assuming this is deliberate. I always assumed it was
> > deliberate.
>
> Although thinking about it more it is weird as hell. You can install
> code into the process, but not have any sign of it in %INC. And later
> code could use that code anyway. Hrm....
>
> Yves
>
>
> --
> perl -Mre=debug -e "/just|another|perl|hacker/"
>


-- 
"At this point, given the limited available data, certainty about only a
very small number of things can be achieved." -- Plato, and others

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