Skip to content

Commit f4a6590

Browse files
committed
Signature.pod tweaks
1 parent 9f1b25c commit f4a6590

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lib/Type/Signature.pod

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ as the parameters were declared.
149149
In the case of named arguments and parameters, only the name is used for
150150
mapping arguments to parameters
151151
152+
=for code :allow<L>
152153
sub named(:$x, :$y) { "x=$x y=$y" }
153-
named( y => 5, x => 4); # x=4 y=5
154+
named( y L«=>» 5, x => 4); # x=4 y=5
154155
155156
It is possible to have a different name for a named parameter than the
156157
variable name:
@@ -163,28 +164,38 @@ Aliases are also possible that way:
163164
sub paint( :color(:colour($c)) ) { } # 'color' and 'colour' are both OK
164165
sub paint( :color(:$colour) ) { } # same API for the caller
165166
166-
167167
=head2 Optional and Mandatory Parameters
168168
169-
Named parameters are optional by default, and can be made mandatory with a
170-
trailing exclamation mark:
171-
172-
:(:$name!) # mandatory 'name' named parameter
173-
174169
Positional parameters are mandatory by default, and can be made optional
175170
with a default value or a trailing question mark:
176171
172+
:(Str $id) # required parameter
177173
:($base = 10) # optional parameter, default value 10
178174
:(Int $x?) # optional parameter, default is the Int type object
179175
180-
Named parameters can also have default values.
176+
Named parameters are optional by default, and can be made mandatory with a
177+
trailing exclamation mark:
178+
179+
:(:%config) # optional parameter
180+
:(:$debug = False) # optional parameter, defaults to False
181+
:(:$name!) # mandatory 'name' named parameter
181182
182183
Default values can depend on previous parameters, and are (at least
183184
notionally) computed anew for each call
184185
185186
:($goal, $accuracy = $goal / 100);
186187
:(:$excludes = ['.', '..']); # a new Array for every call
187188
189+
=head2 Capture Parameters
190+
191+
Prefixing a parameter with a vertical bar C<|> makes the parameter a
192+
L<C<Capture>>, using up all the remaining positional and named
193+
arguments.
194+
195+
This is often used in L<C<proto> definitions|proto> (like C<proto foo (|) {*}>)
196+
to indicate that the routine's L<C<multi> definitions|multi> can have any
197+
L<type constraints|#Type_Constraints>.
198+
188199
=head2 Parameter Traits and Modifiers
189200
190201
By default, parameters are bound to their argument and marked as
@@ -206,14 +217,6 @@ value of the variable at the caller side
206217
($x, $y) = ($y, $x);
207218
}
208219
209-
To bind either to a value or a variable, one can prefix a parameter with
210-
a backslash C<\>.
211-
212-
sub f(\$raw) { ... }
213-
214-
Prefixing a parameter with a vertical bar C<|> makes it use up all the
215-
remaining positional and named arguments.
216-
217220
=head1 Methods
218221
219222
=head2 method params

0 commit comments

Comments
 (0)