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:
Tom Molesworth via perl5-porters
Date:
February 17, 2022 03:31
Subject:
Re: arity checking (was Re: PSC #049 2022-01-07)
Message ID:
CAGXhHdkTF53DVs1xnHa5dFtZWq=MNMygWiFp1FpSoCvq8LunfQ@mail.gmail.com
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)

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