Camelia

class Parameter

src
    class Parameter { }

 
Represents a parameter, for purpose of introspection. The usual way to obtain a Parameter object is to create a signature, and call .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.

Methods

name

Returns the variable name.

constraints

Returns additional constraints on the parameter (usually as an all -Junction).

type

Returns the nominal type constraint of the paramter.

named

Returns True if it's a named parameter.

named_names

Returns a list of names/aliases for this parameter.

positional

Returns True if the parameter is positional.

slurpy

Returns True for slurpy parameters.

optional

Returns True for optional parameters.

parcel

Returns 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.

capture

Returns 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.

rw

Returns True for is rw parameters.

copy

Returns True for is copy parameters.

readonly

Returns True for read-only parameters (the default).

invocant

Returns True if the parameter is the invocant parameter.

default

Returns a closure that upon invocation returns the default value for this parameter, or Any if no default was provided.

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

 

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: