2022-6-15 16:21 Alexander Hartmaier <alex.hartmaier@gmail.com> wrote: > 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? >> >> Keeping the original value _also_ doesn't seem like a good idea, `package >> Example; my $should_drop_out_of_scope = ...;` for example. >> >> I saw those but they confused me. > So require just returns what the loaded file returns? So in case the file > ends in 1;, the return value is 1, but some return a blessed object and > this is returned? > > Is that a feature or a misuse of 'require'? > I also want to know either of the following. 1. "require" ignores the return value of the .pm file to check whether it is successful, and "require" returns builtin::true. 2. "require" ignores the return value of the .pm file to check whether it is successful, and "require" returns the return value of the .pm file.Thread Previous | Thread Next