On Fri, 24 Jun 2022 at 04:52, Graham Knop <haarg@haarg.org> wrote: > On Wed, Jun 22, 2022 at 1:19 AM Yuki Kimoto <kimoto.yuki@gmail.com> 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. > It already returns the last value _if it was true_, so I think this description is a bit misleading - the concern here could be reworded as "require should never return false", since that'd be what breaks the eval { require } combination? Again, I think this is long past any reasonable "pre-RFC" stage, and it'd make more sense to continue the discussion based on a real RFC, but: - `perldoc -f require` includes a Perl implementation of (most of) the require() functionality - that seems like a good starting point to summarise the proposed change as hopefully-unambiguous code Would this be accurate, for example: use Carp 'croak'; use version; sub require { my ($filename) = @_; if ( my $version = eval { version->parse($filename) } ) { if ( $version > $^V ) { my $vn = $version->normal; croak "Perl $vn required--this is only $^V, stopped"; } return 1; } if (exists $INC{$filename}) { return 1 if $INC{$filename}; croak "Compilation failed in require"; } foreach $prefix (@INC) { if (ref($prefix)) { #... do other stuff - see text below .... } # (see text below about possible appending of .pmc # suffix to $filename) my $realfilename = "$prefix/$filename"; next if ! -e $realfilename || -d _ || -b _; $INC{$filename} = $realfilename; my $result = do($realfilename); # but run in caller's namespace if (!defined $result) { $INC{$filename} = undef; croak $@ ? "$@Compilation failed in require" : "Can't locate $filename: $!\n"; } - if (!$result) { + if (!$result and !$^H{require_without_throwing_exceptions_when_false_feature_formerly_described_as_yield_true}) { delete $INC{$filename}; croak "$filename did not return true value"; } + $result ||= builtin::true; $! = 0; return $result; } croak "Can't locate $filename in \@INC ..."; }Thread Previous | Thread Next