develooper Front page | perl.perl5.porters | Postings from February 2023

Re: RFC0013 - how should overload `substr` interact with `nomethod`

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
February 1, 2023 22:26
Subject:
Re: RFC0013 - how should overload `substr` interact with `nomethod`
Message ID:
20230201222627.1ffba176@shy.leonerd.org.uk
On Tue, 24 Jan 2023 16:58:10 +0000
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> Perhaps it could be solved by a dual-life-capable "overload::v2" which
> is shipped by newer perls and can be CPAN shimmed around older ones:
> 
>   use overload::v2
>     nomethod => sub ($self, $ctx, @args) { ... };

Having discussed this more in the PSC meeting, this feels like probably
the best way forward actually.

Bikeshedding needs to happen on exactly what the module name should be,
but overall this feels best. A new module that can be shipped with core
perl but also live on CPAN dual-life for older perls. It would act as
a little shim around the calling-convention of the callbacks, adapting
them all to a newer better shape, whereby the arg shape is always of
that form:

  ($self, $ctx, @args)

where $ctx stores a standard "overloading context" object having some
methods to carry things like the op name and the swapped flag, and
@args contains just everything else that would have been visible as
perl-level arguments. So unops see nothing else there, binops see
$other, and new stuff like substr or whatever would see the other
values.

The context being an object with methods on it makes a much easier
place to attach other information in future, as new named methods can
easily be added to it.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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