1Signature(3)          User Contributed Perl Documentation         Signature(3)
2
3
4

NAME

6       perl5i::Signature - Representing what parameters a subroutine accepts
7

SYNOPSIS

9           func hello( $greeting, $place ) { say "$greeting, $place" }
10
11           my $code = \&hello;
12           my $signature = $code->signature;
13
14           say $signature->num_positional_params;  # 2
15           say $signature->is_method;   # false
16

DESCRIPTION

18       A Signature is a representation of what parameters a subroutine
19       accepts.  Each subroutine defined with "func" or "method" will have a
20       signature associated with it.  You can get at it by calling the
21       "signature" method on the code reference.  See "Signature
22       Introspection" in perl5i for more details.
23
24       Subroutines declared with Perl's built in "sub" will have no signature.
25

METHODS

27       params
28
29           my $params = $sig->params;
30
31       An array ref of the parameters a subroutine takes in the order it takes
32       them.  Currently they are just strings.  In the future they will be
33       string overloaded objects.
34
35       positional_params
36
37           my $params = $sig->positional_params;
38
39       Like "$sig->params" but it is just the positional parameters.
40
41       In the future there will be named parameters.
42
43       num_positional_params
44
45           my $num_positional_params = $sig->num_positional_params;
46
47       The number of named parameters the subroutine takes.
48
49       In the future there will be named parameters.  For the purposes of
50       determining how many arguments a function takes, it is most useful to
51       look just at the positional ones.
52
53       This is mostly an optimization for "$sig->positional_params->size".
54
55       as_string
56
57           my $params = $sig->as_string;
58
59       The original signature string.
60
61       invocant
62
63           my $invocant = $sig->invocant;
64
65       The invocant is the object or class a method is called on.  "invocant"
66       will return the parameter which contains this, by default it is $self
67       on a method, and nothing a regular subroutine.
68
69       is_method
70
71           my $is_method = $sig->is_method;
72
73       Returns if the subroutine was declared as a method.
74

OVERLOADING

76       Signature objects are string overloaded to return "as_string".  They
77       are also always true to avoid objects taking no parameters from being
78       confused with subroutines with no signatures.
79
80
81
82perl v5.30.0                      2019-07-26                      Signature(3)
Impressum