New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Perl 7: don't require modules to return true #17921
Comments
My disagreement with the idea of default enabling features notwithstanding, this would be a very useful feature to add, and I am not sure it even needs a feature flag. |
Even better IMO would be if the return value of a
This would mean that Perl (7) would have to cache the return value to make it available to all locations. |
That is possible for require, but use is a compile time statement which physically cannot be used in a runtime expression (except via string eval which is definitely not something we should be encouraging). |
Yeah - I think |
That's a nice idea but aren't you conflating modules and packages? Require can say "the eval of this module was successful". It doesn't know what packages in the module were eval'd. |
Yes, but what is returned is still up to the module. Maybe it returns a hash mapping functionality to class names, or whatever. But for the simple use case of a single classname that is exported from a module file, this would already be useful. |
Ah I think I see, you're proposing that package Foo;
{ packages => ['Foo'] }
|
Not quite. It only returns the last value the first time a file is required.
So you can't really rely on require to return anything useful, other than its return value being almost certainly true. (With some careful use of overloading, it might be possible to return an object that |
I just came to add my +1 to this idea. I think it's a great modernization. |
I can think of 3 ways it could be done:
What do you think? Would compiling a custom 5.32 Perl with this feature removed and running a cpantesters server, comparing the results to 5.32 cpantester results be a good way to gauge the impact? |
A module at |
In this scenario the user must have knowledge that the module has this quirk; otherwise it wouldn't know to retry when it fails to load. It must also be calling package Foo;
sub bar { print "Foobar\n" }
die "reload me\n" if time % 2;
1; use strict;
use warnings;
use Time::HiRes 'sleep';
do {
delete $INC{'Foo.pm'};
eval { require Foo };
} while ($@ =~ /reload/);
Foo->bar;
A better way to be sure you have loaded a file over a network (or another unreliable interface) would be to use a checksum. Relying on Even though I think this is misfeature, I agree that some users' code may depend on this behavior. I've proposed 2 ways we can mitigate that (via deprecation, via a feature). But I don't think it is common. As there is already a more powerful way to handle conditional load without relying on require returning true, I think we should optimize for the common case here and stop littering our modules with extra boilerplate. |
Can we change Perl 7 to stop requiring modules to return true?
I wrote about this previously:
Module authors are free to continue appending
1;
to their modules, and they will continue to work; Perl won't just demand it anymore :)For the rare cases where authors depend on that behavior, it could be implemented as a feature which could be enabled by default in Perl 7. That is how I did it in the article.
If we agree this is an appropriate change, I'm happy to rebase and submit a PR but wanted to ask first.
Thanks
The text was updated successfully, but these errors were encountered: