Do you want the minimum number of arguments that must be specified, or the miminum number of arguments that must be passed to the function?
# Minimum number of arguments that must be specified = 0
# Miminum number of arguments that must be passed = 1
sub f(_) {}
# Minimum number of arguments that must be specified
sub get_min_require_params {
my ($sub) = @_;
my $required_params = 0;
my $prototype = prototype($sub);
return 0 if !defined($prototype);
for ($prototype) {
if (/
\G
(?: \$
| \*
| \\(?: \[ [^\]] \] | [^\[] )
| \&
)
/xsgc) {
++$required_params;
next;
}
if (/
\G
(?: \_ # Can only be followed by ";"
| \@
| \%
| \;
| \z
/xsgc) {
last;
}
die("Unrecognized prototype\n");
}
}
To get the minimum number of arguments that must be passed to the function, you'll need to move "_" to the top "if".
I don't see how either version is useful, so I'm sure there's an XY problem lurking.
perlsub (for info on prototypes), prototype
|