Re: Idea / preRFC - return value of require
[email protected] (Branislav ZahradnĂk) Thu, 12 Feb 2026 15:19:25 +0100
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <CAB=rbOnAryTxge1MfpOwx12FVWzD0ArYvpN0O2+XHR+YK=Vxag@mail.gmail.com> |
On Thu, 12 Feb 2026 at 15:03, Paul "LeoNerd" Evans <[email protected]> wrote: > On Thu, 12 Feb 2026 14:35:52 +0100 > Branislav ZahradnĂk <[email protected]> wrote: > > > Expectation: > > - first call of function will load specified module > > - subsequent call of function will always return same value as first > > call > > > > Current behaviour: > > - subsequent call returns value true if require was successful > > - if package-block is used, it doesn't return value of last statement > > of block but only logical true/false > > It is this way intentionally. > > Otherwise, you have the problem of unexpected extra reference counts of > returned values. If your final statement in the file scope yields some > large data structure, or object that's supposed to have timely > destruction semantics, or somesuch, then the cache will retain it for > too long. > This is exactly behaviour I want in this idea. I will be fine with expression `require :cached Foo` (naming is not important, behaviour is) > > If you did want a way to load a FILE and reliably return the value from > its final expression, you wanted `do FILE`. > that is tons of code I don't want to write. Yes, I can do: sub { require Foo; Foo->value } but that is additional number of tokens I want to avoid. > > -- > Paul "LeoNerd" Evans > > [email protected] > http://www.leonerd.org.uk/ | https://metacpan.org/author/PEVANS >