Function::Parameters::Info - Information about parameter lists
use Function::Parameters; fun foo($x, $y, :$hello, :$world = undef) {} my $info = Function::Parameters::info \&foo; my @p0 = $info->invocants; # () my @p1 = $info->positional_required; # ('$x', '$y') my @p2 = $info->positional_optional; # () my @p3 = $info->named_required; # ('$hello') my @p4 = $info->named_optional; # ('$world') my $p5 = $info->slurpy; # undef my $min = $info->args_min; # 4 my $max = $info->args_max; # inf my @invocants = Function::Parameters::info(method () { 42 })->invocants; # ('$self') my $slurpy = Function::Parameters::info(fun (@) {})->slurpy; # '@'
Function::Parameters::info returns objects of this class to describe parameter lists of functions. See below for "Parameter Objects". The following methods are available:
Function::Parameters::info
Returns a list of parameter objects for the variables into which initial arguments are shifted automatically (or a count in scalar context). This will usually return () for normal functions and ('$self') for methods.
shift
()
('$self')
Returns a list of parameter objects for the required positional parameters (or a count in scalar context).
Returns a list of parameter objects for the optional positional parameters (or a count in scalar context).
Returns a list of parameter objects for the required named parameters (or a count in scalar context).
Returns a list of parameter objects for the optional named parameters (or a count in scalar context).
Returns a parameter object for the final array or hash that gobbles up all remaining arguments, or undef if no such thing exists.
undef
Returns the minimum number of arguments this function requires. This is computed as follows: Invocants and required positional parameters count 1 each. Optional parameters don't count. Required named parameters count 2 each (key + value). Slurpy parameters don't count either because they accept empty lists.
Returns the maximum number of arguments this function accepts. This is computed as follows: If there are any named or slurpy parameters, the result is Inf. Otherwise the result is the number of all invocants and positional parameters.
Inf
Similar to "$info->invocants" above: Returns undef if the number of invocants is 0, a parameter object for the invocant if there is exactly 1, and throws an exception otherwise.
Many of the methods described above return parameter objects. These objects have two methods: name, which returns the name of the parameter (as a plain string), and type, which returns the corresponding type constraint object (or undef if there was no type specified).
name
type
This should be invisible if you don't care about types because the objects also overload stringification to call name. That is, if you treat parameter objects like strings, they behave like strings (i.e. their names).
Function::Parameters
Lukas Mai, <l.mai at web.de>
<l.mai at web.de>
Copyright 2013, 2016 Lukas Mai.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Function::Parameters, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Function::Parameters
CPAN shell
perl -MCPAN -e shell install Function::Parameters
For more information on module installation, please visit the detailed CPAN module installation guide.