develooper Front page | perl.perl5.porters | Postings from July 2018

Re: Allowing require to return false

Thread Previous | Thread Next
John Imrie via perl5-porters
July 28, 2018 11:00
Re: Allowing require to return false
Message ID:

On 27/07/2018 01:02, James E Keenan wrote:
> On 07/26/2018 12:43 PM, Dave Mitchell wrote:
>> On Wed, Jul 25, 2018 at 09:56:12AM -0400, David Farrell wrote:
>>> Frustratingly, I don't know if any of these are worth pursuing - I 
>>> wonder
>>> if anyone would write modules that didn't return a true value as they
>>> wouldn't work on past versions of Perl. If we assume Perl is going 
>>> to be
>>> used for another 25 years, then maybe it's worth it.
>> I'm opposed to making any change here.
>> It's an annoying but trivial little quirk that people have to remember.
>> If we change it (such as adding adding a feature, or use v5.30) then for
>> the next 20 years people have to remember *2* quirks instead.
>> Just removing it altogether might not break *many* modules, but why 
>> break
>> *anything* for so little gain?
> +1
> 1;
There may be a way of implementing this with out too much trouble.
1st make it controlled by a feature inside the module, which means that 
it wont break old code
2nd If require is called in void context assume that the last line of 
the module was '0 but true'; iff the module returns a false value;
3rd Anything else works as before

This allows you to write modules like
package Module;
use v5.30;
# my stuff

And the following in your main code
use v5.30;
require Module; # Assumes that Module returns '0 but true'
if (require Module) {
     # Called in boolean context so '0 but true' is not added to the end 
of the module

However if Module is written as
package Module;
use v5.30;
# my stuff

The require will return 3 in all contexts


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