Re: Idea / preRFC - return value of require
[email protected] (Aristotle Pagaltzis via perl5-porters) Thu, 12 Feb 2026 16:18:33 +0100
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
* Branislav Zahradník <[email protected]> [2026-02-12 14:40]: > - feature will be become handy when require will support dynamic > loading, eg like: > ``` > require :module $plugin; > ``` Actually that’s when the feature becomes unnecessary, because the only reason I can see (and I’ll grant that it’s annoying) is that you have to either live with duplicating the package name require Some::Long::Winded::Name; Some::Long::Winded::Name->value or write something very ugly like require $package =~ s!::!/!gr . '.pm'; $package->value If you could literally do require $package; $package->value then that *would* be how you should do it, not by fiddling with the `require` return value. 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. -- Aristotle Pagaltzis // <http://plasmasturm.org/>