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

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

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

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

Ahyes :)

So armed with this knowledge I have now created

  https://metacpan.org/pod/Sub::Attribute::Prototype

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

Ahyes, an annoying caveat. That and the other two are noted in the docs:

  https://metacpan.org/pod/Sub::Attribute::Prototype#Caveats

Because of these limitations, I'm probably not even going to convert my
own modules (e.g. List::UtilsBy) into using this one yet. I'd welcome
anyone trying to help improve the situation and get rid of these
problems, but currently it seems I shall have to leave List::UtilsBy in
a 7-unsafe state.

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