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

Re: Dual-life perl 5-or-7 code and prototypes - impossible?

Thread Previous
From:
Paul "LeoNerd" Evans
Date:
June 27, 2020 19:26
Subject:
Re: Dual-life perl 5-or-7 code and prototypes - impossible?
Message ID:
20200627202611.72c2f04f@shy.leonerd.org.uk
On Sat, 27 Jun 2020 19:29:42 +0100
ilmari@ilmari.org (Dagfinn Ilmari Mannsåker) wrote:

> attributes.pm says:
> 
>     The call to [the MODIFY_type_ATTRIBUTES] method is currently made
>     during the processing of the declaration.  In particular, this
> means that a subroutine reference will probably be for an undefined
>     subroutine, even if this declaration is actually part of the
>     definition.

Hrm; I don't suppose then any way we can work around that inside the XS
code of Sub::Util::set_prototype itself, if perl is only going to splat
over it anyway.

> >  1) This code has to suppress all "reserved" warnings, not just
> > those relating to the :prototype attribute

Any way to address this one?

> >  2) This code has to appear in List/UtilsBy.pm directly because of
> > that UNITCHECK phaser. It would not be possible to inject this
> > entire thing via a module.  
> 
> The B::CompilerPhase::Hook module lets you programmatically enqueue
> phasers: https://metacpan.org/pod/B::CompilerPhase::Hook.
> 
> Sticking the above code in a Sub::Attribute::Prototype::import() and
> replacing UNITCHECK { ... } with enqueue_UNICHECK(sub { ...}) works.

Ahah, well that's progress. It is an out-of-core XS module, which might
be a bit of a hard sell for trying to make a compat. mechanism for
*every* prototype-using CPAN module to be using, but I can give it a go
and see how it works.

> Hoewver, another issue is that because the prototype isn't set until
> UNITCHECK time, it will not apply to calls in the same unit as the
> prototyped sub is defined in, so this is really only useful for
> modules that export subs, not scripts.

That's still a good start. I think in practice none of the
List::UtilsBy functions call each other, so it will work for my
use-case, and probably a decent fraction of prototype-using CPAN
modules. Some BIG LOUD WARNINGS can be put into the docs of such a
still-hypothetical Sub::Attribute::Prototype in any case.

-- 
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


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