in reply to Re^6: Distinguish between missing and undefined arguments with subroutine signatures (semipredicate problem)
in thread Distinguish between missing and undefined arguments with subroutine signatures

> It does not prevent the sub from being called with more arguments than allowed.

Wait a second....

If you are talking about compile-time checking a ->method I'm pretty sure that this can't be done in dynamically typed languages like Perl.

Like with prototypes I expect this only to be possible with normal subs. ( without static typing of the $obj it's impossible to tell which ->methods are allowed, normal subs OTOH can be pre-declared.)

And when doing a dynamic check at run-time, using a @slurpy array is just good enough.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^7: Distinguish between missing and undefined arguments with subroutine signatures (methods with signatures?)
  • Select or Download Code

Replies are listed 'Best First'.
Re^8: Distinguish between missing and undefined arguments with subroutine signatures (methods with signatures?)
by jo37 (Curate) on Dec 27, 2020 at 21:53 UTC
    If you are talking about compile-time checking ...

    No, I'm not talking about compile-time checking. I want method call checking at runtime. My sig_lexical example does what I want, but I'm not sure if this is a legal usage.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      > I want method call checking at runtime

      I can't follow anymore.

      You want 1 argument for a setter, and 0 arguments for a getter.

      Hence you need a conditional check anyway.

      So use a @slurpy parameter and check the size at runtime.

      Then die "too many arguments" if @slurpy > 1

      Problem solved.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery