/
Parameter.pod
107 lines (62 loc) 路 2.24 KB
/
Parameter.pod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
=begin pod
=TITLE class Parameter
class Parameter { }
Represents a parameter, for purpose of introspection.
The usual way to obtain a Parameter object is to create a signature,
and call C<.params> on it to obtain a list of the Parameters.
my $sig = :(Str $x);
my $param = $sig.params[0];
say $sig.type; # Str()
See L<Signature> for more information, and also for an explanation
on what most of the concepts related to parameters mean.
=head1 Methods
=head2 name
Returns the variable name.
=head2 constraints
Returns additional constraints on the parameter (usually as an
C<all>-Junction).
=head2 type
Returns the nominal type constraint of the paramter.
=head2 named
Returns C<True> if it's a named parameter.
=head2 named_names
Returns a list of names/aliases for this parameter.
=head2 positional
Returns C<True> if the parameter is positional.
=head2 slurpy
Returns C<True> for slurpy parameters.
=head2 optional
Returns C<True> for optional parameters.
=head2 parcel
Returns C<True> for parcel parameters.
sub f(\$parcel) {
$parcel = 5;
}
f(my $x); # works
f(42); # dies in the assignment
Parcel parameters bind either a variable or a value passed to it, with
no decontainerization happen. That means that if a variable was passed
to it, you can assign to the parameter. This is different from
L<rw|#rw>-parameter which can only bind to variables, never to values.
=head2 capture
Returns C<True> for parameters that capture the rest of the argument list.
sub f(\capture) { }
Capture parameters do not force any context on the values passed bound
to them, which is why they cannot have sigils.
=head2 rw
Returns C<True> for C<is rw> parameters.
=head2 copy
Returns C<True> for C<is copy> parameters.
=head2 readonly
Returns C<True> for read-only parameters (the default).
=head2 invocant
Returns C<True> if the parameter is the invocant parameter.
=head2 default
Returns a closure that upon invocation returns the default value for
this parameter, or C<Any> if no default was provided.
=head2 type_captures
Returns a list of variable names of type captures associated with this
parameter.
sub a(::T ::U $x) { }
say &a.signature.params[0].type_captures; # T U
=end pod