Documentation for trait is copy

Documentation for trait is copy, assembled from the following types:

class Signature

From Signature

(Signature) trait is copy

By default, parameters are bound to their argument and marked as read-only. One can change that with traits on the parameter.

The is copy trait causes the argument to be copied, and allows it to be modified inside the routine

sub count-up($x is copy{
    $x = Inf if $x ~~ Whatever;
    .say for 1..$x;
}

The is rw trait makes the parameter bind to a variable (or other writable container). Assigning to the parameter changes the value of the variable at the caller side.

sub swap($x is rw$y is rw{
    ($x$y= ($y$x);
}

On slurpy parameters, is rw is reserved for future use by language designers.

The is raw trait is automatically applied to parameters declared with a backslash as a "sigil", and may also be used to make normally sigiled parameters behave like these do. In the special case of slurpies, which normally produce an Array full of Scalars as described above, is raw will instead cause the parameter to produce a List. Each element of that list will be bound directly as raw parameter.

To explicitly ask for a read-only parameter use the is readonly trait. Please note that this applies only to the container. The object inside can very well have mutator methods and Perl 6 will not enforce immutability on the attributes of the object.

Traits can be followed by the where clause:

sub ip-expand-ipv6($ip is copy where m:i/^<[a..f\d\:]>**3..39$/{ }