Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

108 lines (62 sloc) 2.293 kb
=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
=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
sub a(::T ::U $x) { }
say &a.signature.params[0].type_captures; # T U
=end pod
Jump to Line
Something went wrong with that request. Please try again.