develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
Graham Knop
June 23, 2022 20:52
Re: Pre-RFC: yield true feature
Message ID:
On Wed, Jun 22, 2022 at 1:19 AM Yuki Kimoto <> wrote:
> Summary.
> Are we going in the following direction?
> If the "yield_true" feature is enabled,
>   - the effect is local-scope. Generally the "yield_true" feature is used at the top level file scope.
>   - It has no effect on the return value of .pm file. Both an implicit return value and an explicit return value specified by return statement.
>   - "require" ignores the return value to determine if the module was successfully loaded.
>   - "require" returns the return value of .pm file just like the current behavior.

I think having require return the last value from the file would be a
terrible change.

Currently, require will always return a true value, because anything
else will croak. There is plenty of code that relies on this. For

if (eval { require $module }) { ... }

This has always been a reliable way to check if the module could be
loaded. If require continues to return the (possibly false) value from
the file, plenty of code will break. In fact, using the return value
of require as a true value has been the only reliable use of its
return value, since it will not return the "last value" after the
first call to require for a given file.

I strongly believe that when require loads a file that is using this
feature, it should ignore the final value from the module and instead
return a standard boolean true.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About