Re: Idea / preRFC - return value of require

[email protected] (Marco Fontani) Thu, 12 Feb 2026 16:28:05 +0100
Newsgroups perl.perl5.porters
Message-ID <CANNjYqXBJ5-WybVF6yDMpF8hJkRTdRoYW2pu2tPzqdc=4FZP3Q@mail.gmail.com>
On Thu, 12 Feb 2026 at 16:19, Aristotle Pagaltzis via perl5-porters
<[email protected]> wrote:
> If we were starting over from scratch I would consider making `require`
> *always* return the package name, instead of either the last expression
> value (initially) or PL_sv_yes (subsequently) and that would make this
> code even shorter:
>
>     ( require $package )->value
>
> But the fact that `require` initially returns the last expression value
> cannot be changed now, which makes it useless to change what it returns
> subsequently, because the code would still have to account for two cases
> anyway, so there is nothing to be gained.
>
> I think your answer is you put the ugly version in a helper function and
> use that.

Or use builtin::load_module, which _does_ return the package name that
it loaded:

    Loads a named module from the inclusion paths (@INC). $module_name must
    be a string that provides a module name. It cannot be omitted, and
    providing an invalid module name will result in an exception. Not
    providing any argument results in a compilation error. Returns the
    loaded module's name on success.


-- 
Marco Fontani
+39-329-2180550
perl -E'say v74.65.80.72'