develooper Front page | perl.perl5.porters | Postings from September 2021

Re: module loading built-in

Thread Previous | Thread Next
From:
Dan Book
Date:
September 12, 2021 17:33
Subject:
Re: module loading built-in
Message ID:
CABMkAVXZoH6EPnYxQwdQ3JpBFHch5kZ6SE3ParynTf=BM9GcLg@mail.gmail.com
On Sun, Sep 12, 2021 at 1:27 PM Felipe Gasper <felipe@felipegasper.com>
wrote:

>
>
> On Sep 12, 2021, at 12:36, Dan Book <grinnz@gmail.com> wrote:
>
> 
> On Sun, Sep 12, 2021 at 12:23 PM Felipe Gasper <felipe@felipegasper.com>
> wrote:
>
>>
>> If I may, another suggestion/request: have the built-in return the
>> namespace itself. This way it’s easy to do stuff like:
>>
>> my $class = 'My::Class';
>> my $thing = need($class)->new();
>>
>
> This is easily sensible for the version which only returns or dies like
> require, which does not have a need for a significant return value
> (use_module from Module::Runtime does this). A version which uses the
> return value to indicate whether it was successful could also use the
> package name as the "success" return value, only because '' and '0' are not
> valid package names.
>
>
> There are enough reasons for “I can’t do that, Dave” when loading a module
> that ISTM a return-in-failure would have granularity problems.
>
> I think the most natural interface is computer-friendly exceptions of some
> kind: objects, code-prefixed strings, etc.
>

Yes, exception objects would be a solution. But I am talking about the
interface described in the rest of the thread. Exceptions would be thrown
for issues other than missing module or insufficient version; only in those
cases would false be returned.

-Dan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About