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

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
From:
Graham Knop
Date:
June 14, 2022 21:52
Subject:
Re: Pre-RFC: yield true feature
Message ID:
CAM=m89E5DgX8X8Tu6uMG3MkemtmnVOqSWhhXdR5g_ymmiBRUkg@mail.gmail.com
On Tue, Jun 14, 2022 at 7:10 PM Tom Molesworth <tom@deriv.com> wrote:
>
> On Wed, 15 Jun 2022 at 00:13, Graham Knop <haarg@haarg.org> wrote:
>>
>> On Tue, Jun 14, 2022 at 6:02 PM Alexander Hartmaier
>> <alex.hartmaier@gmail.com> wrote:
>> >
>> > On Tue, Jun 14, 2022 at 11:33 AM Graham Knop <haarg@haarg.org> wrote:
>> >>
>> >> On Tue, Jun 14, 2022 at 8:15 AM Alexander Hartmaier
>> >> <alex.hartmaier@gmail.com> wrote:
>> >> > Look at some of the other modules using the return value of require from the grep.metacpan.org link.
>> >>
>> >> Do you have a concrete example?
>
>
> There are plenty of cases which are effectively "`require` is used instead of `do`", i.e. calling `require` and the subsequent code relies on the data, rather than truth of the return value.
>
> Some examples from just the first page of results - there are others on that page:
>
> https://grep.metacpan.org/search?qci=&q=%3D%20require&qft=&qd=AWS-Lambda
>
> my $app = require "$ENV{'LAMBDA_TASK_ROOT'}/app.psgi";
> my $func = AWS::Lambda::PSGI->wrap($app);
>
> https://grep.metacpan.org/search?qci=&q=%3D%20require&qft=&qd=App-Alice
>
>   my $config = {};
>   if (-e $self->fullpath) {
>     $config = require $self->fullpath;
>
> https://grep.metacpan.org/search?qci=&q=%3D%20require&qft=&qd=App-Chart
>
> my $aref = require App::Chart::Gtk2::IndicatorModelGenerated;
>
> All of these are somewhat fragile: call the code twice or have something else `require` the relevant module/file first, and they'd have problems. However, given how often this pattern appears, require-returns-`builtin::true` may be too disruptive if strictly enforced?

It would not be strictly enforced. It would only happen if the file
being required did `use v5.40;` or such a declaration. Most of these
cases would likely never add that declaration, and new code that did
would not be able to be used in this fragile way. If someone did add
such a declaration to their existing code, it would cause these uses
to immediately fail, which I see as an acceptable outcome.

>
> Keeping the original value _also_ doesn't seem like a good idea, `package Example; my $should_drop_out_of_scope = ...;` for example.
>

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