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

Re: arity checking (was Re: PSC #049 2022-01-07)

Thread Previous | Thread Next
From:
Yuki Kimoto
Date:
February 18, 2022 04:17
Subject:
Re: arity checking (was Re: PSC #049 2022-01-07)
Message ID:
CAExogxPZxHb1XhGzLY+R9Ayt_B0QNO+NyBUqdvYLtt-6G9BcRg@mail.gmail.com
2022-2-17 12:31 Tom Molesworth <tom@deriv.com> wrote:

> On Thu, 17 Feb 2022 at 11:19, Yuki Kimoto <kimoto.yuki@gmail.com> wrote:
>
>> In order that the module author pass arguments safely, dual life module "
>> buildin.pm" and the function to pass arguments safely.
>>
>>   # Pass arguments safely
>>   package Foo;
>>
>>   use builtin 'call_cb_safe';
>>
>>   sub execute {
>>     my ($cb) = @_;
>>
>>     # Pass arguments safely
>>     call_cb_safe($cb, (1, 2));
>>   }
>>
>
> Yes, but this has been covered several times on the list recently.
>
> See https://metacpan.org/pod/Acme::Signature::Arity#coderef_ignoring_extra
> for this specific case - I think your example would look like this:
>
>   package Foo;
>
>   use Acme::Signature::Arity qw(coderef_ignoring_extra);
>
>   sub execute {
>     my ($cb) = @_;
>
>     # Pass arguments safely
>     coderef_ignoring_extra($cb)->(1, 2);
>   }
>
> (or use `min_arity`/`max_arity` to apply different rules)
>
>
Tom

Oh, You have already mentioned it.

I understand how to use coderef_ignoring_extra now.

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