Re: Signature Named Parameters and `meta` Queries
[email protected] ("Paul \"LeoNerd\" Evans")
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 12 Nov 2025 17:40:53 +0000 Harald Jörg <[email protected]> wrote: > I would prefer if min_args and max_args count positional arguments > only, and named parameters are only available using the named_params > method. Consider the following signature: Oh, we already have "mandatory_params" and "optional_params" accessors that count the positional ones. The point with min/max is more to indicate that numbers outside of this range are definitely, absolutely errors. > sub from_file ($class, :$path) { ... } > > Having "min" and "max" suggests that any number inbetween is valid to > be passed by the caller. This is not the case if you count named > parameters: The number of parameters has be odd, however often you > provide a 'path => somewhere,'. Mmm, yes the arity is already an interesting question. But that also comes up without named ones when you consider slurpy hashes. > I admit that I currently have no use for meta operations on signatures > (OTOH, I would very much welcome introspection of classes). Hmmmyes I should look into that sometime. I'm hesitant to add *too* much more to the `meta` API shape right now though until some more basic questions have been answered - like the problems surrounding get-or-fail, vs get-or-undef semantics on a lot of the accessors. > My > current use of named parameters is for alternate constructors, so I > have always one mandatory positional argument and then some named > ones. Named parameters in the signature take a lot of runtime > validation work from me compared to the "old" signature > ($class,%params). Speaking of alternate constructors, you may wish to be aware of https://metacpan.org/pod/Object::Pad#%3Alexical_new The intention there being you can hide the default-provided constructor and wrap it in your own provided methods. In fact if you're a bit subtle about it you can even provide a visible method named `new` ;) class PointOverridingNew :lexical_new { method new :common { my ( $x, $y ) = @_; return new( __PACKAGE__, x => $x, y => $y ); } field $x :param :reader; field $y :param :reader; } I'm intending to bring `:abstract` and `:lexical_new` into the core feature class work soon, once I have slightly improved the overall situation with attributes generally. -- Paul "LeoNerd" Evans [email protected] http://www.leonerd.org.uk/ | https://metacpan.org/author/PEVANS