1Function::Parameters::IUnsfeor(3C)ontributed Perl DocumeFnutnacttiioonn::Parameters::Info(3)
2
3
4

NAME

6       Function::Parameters::Info - Information about parameter lists
7

SYNOPSIS

9         use Function::Parameters;
10
11         fun foo($x, $y, :$hello, :$world = undef) {}
12
13         my $info = Function::Parameters::info \&foo;
14         my @p0 = $info->invocants;            # ()
15         my @p1 = $info->positional_required;  # ('$x', '$y')
16         my @p2 = $info->positional_optional;  # ()
17         my @p3 = $info->named_required;       # ('$hello')
18         my @p4 = $info->named_optional;       # ('$world')
19         my $p5 = $info->slurpy;               # undef
20         my $min = $info->args_min;  # 4
21         my $max = $info->args_max;  # inf
22
23         my @invocants = Function::Parameters::info(method () { 42 })->invocants;
24         # ('$self')
25
26         my $slurpy = Function::Parameters::info(fun (@) {})->slurpy;  # '@'
27

DESCRIPTION

29       "Function::Parameters::info" returns objects of this class to describe
30       parameter lists of functions. See below for "Parameter Objects".  The
31       following methods are available:
32
33       $info->invocants
34
35       Returns a list of parameter objects for the variables into which
36       initial arguments are "shift"ed automatically (or a count in scalar
37       context). This will usually return "()" for normal functions and
38       "('$self')" for methods.
39
40       $info->positional_required
41
42       Returns a list of parameter objects for the required positional
43       parameters (or a count in scalar context).
44
45       $info->positional_optional
46
47       Returns a list of parameter objects for the optional positional
48       parameters (or a count in scalar context).
49
50       $info->named_required
51
52       Returns a list of parameter objects for the required named parameters
53       (or a count in scalar context).
54
55       $info->named_optional
56
57       Returns a list of parameter objects for the optional named parameters
58       (or a count in scalar context).
59
60       $info->slurpy
61
62       Returns a parameter object for the final array or hash that gobbles up
63       all remaining arguments, or "undef" if no such thing exists.
64
65       $info->args_min
66
67       Returns the minimum number of arguments this function requires. This is
68       computed as follows: Invocants and required positional parameters count
69       1 each.  Optional parameters don't count. Required named parameters
70       count 2 each (key + value). Slurpy parameters don't count either
71       because they accept empty lists.
72
73       $info->args_max
74
75       Returns the maximum number of arguments this function accepts. This is
76       computed as follows: If there are any named or slurpy parameters, the
77       result is "Inf".  Otherwise the result is the number of all invocants
78       and positional parameters.
79
80       $info->invocant
81
82       Similar to "$info->invocants" above: Returns "undef" if the number of
83       invocants is 0, a parameter object for the invocant if there is exactly
84       1, and throws an exception otherwise.
85
86       Parameter Objects
87
88       Many of the methods described above return parameter objects.  These
89       objects have two methods: "name", which returns the name of the
90       parameter (as a plain string), and "type", which returns the
91       corresponding type constraint object (or undef if there was no type
92       specified).
93
94       This should be invisible if you don't care about types because the
95       objects also overload stringification to call "name". That is, if you
96       treat parameter objects like strings, they behave like strings (i.e.
97       their names).
98

SEE ALSO

100       Function::Parameters
101

AUTHOR

103       Lukas Mai, "<l.mai at web.de>"
104
106       Copyright 2013, 2016 Lukas Mai.
107
108       This program is free software; you can redistribute it and/or modify it
109       under the terms of either: the GNU General Public License as published
110       by the Free Software Foundation; or the Artistic License.
111
112       See http://dev.perl.org/licenses/ for more information.
113
114
115
116perl v5.32.1                      2021-01-27     Function::Parameters::Info(3)
Impressum