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

Re: Pre-RFC: yield true feature

Thread Previous | Thread Next
Graham Knop
June 13, 2022 10:43
Re: Pre-RFC: yield true feature
Message ID:
On Mon, Jun 13, 2022 at 12:21 PM Alexander Hartmaier
<> wrote:
> On Sat, Jun 11, 2022 at 10:37 AM Neil Bowers <> wrote:
>> > Can someone show an example, ideally on CPAN, where this gets used?
>> I _think_ you were asking for an example of someone using the return value from a require. In which case:
>> This is in BooK’s Acme::MetaSyntactic::unicode module (yeah, Acme):
>>     if ( $] >= 5.006 && $] < 5.007003  ) {
>>         eval { $data = require 'unicode/'; };
>>     }
>>     elsif ( $] >= 5.007003 ) {
>>         eval { $data = require 'unicore/'; };
>>         # since v5.11.3, unicore/ creates subroutines
>>         # they end up in our namespace, so get rid of them
>>         undef *code_point_to_name_special;
>>         undef *name_to_code_point_special;
>>     }
>> Guessing there may be other examples on CPAN – this is just the first one I found with
>> Neil
> Thanks for the link, haven't thought about it for finding examples. I've looked at some others and using the return value of a require call is used quite frequently. So option 3 isn't a good one in my opinion, as a module changed to use the feature, most probably with 'use v5.38;' not thinking about the enabled feature, which would lead to another module failing because of the changed behavior.

Anything relying on the return value of require as being anything
other than true is already broken. The second time require is called
for a module, it will turn true, not whatever the module tried to
return. unicode/ is meant to be loaded via do, not require, in
addition to being internal only.

Going back to perl 5.30, the last version Acme::MetaSyntactic passed
its tests on, it still fails if you cause to be loaded early.

$ perl -e'use strict; use warnings; use charnames qw(greek); use
Acme::MetaSyntactic; my $meta = Acme::MetaSyntactic->new("unicode");
die "no names!" if !$meta->name;'
no names! at -e line 1.

I'd say it's better to cause these things to always fail, rather than
allowing them to sometimes appear to work.

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