perl6/doc/lib/Capture

doc src
(title) class Capture
    class Capture does Positonal does Associative { }

 
A Capture is a an argument list for passing it to a code object. It contains a list-like part for positional arguments and a hash-like part for named arguments. Captures can be created by prefixing a term with a backslash \ .
    my $c = \42;            # Capture with one positional parts
    $c = \(1, 2, a => 'b'); # Capture wit two positional and one named part

 
Another common way to create a Capture is to prefix a sigilless parameter with a vertical bar | , which packs the remainder of the argument list into that parameter.
    f(1, 2, 3, a => 4, b => 5);
    sub f($a, |c) {
        # c  is  \(2, 3, a => 4, b => 5)
    }

 

Methods

(head2) list
    method list(Capture:D:) returns Positional

 
Returns the positional part of the Capture.
(head2) hash
    method hash(Capture:D:) returns Associative

 
Returns the named/hash part of the Capture.
(head2) elems
    method elems(Capture:D:) returns Int:D

 
Returns the number of positional elements in the Capture.

Perl 6 Tricks and Treats newsletter

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