method Capture

Documentation for method Capture assembled from the following types:

role Callable

From Callable

(Callable) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class Range

From Range

(Range) method Capture

Defined as:

method Capture(Range --> Capture:D)

Returns a Capture with values of .min .max, .excludes-min, .excludes-max, .infinite, and .is-int as named arguments.

class ComplexStr

From ComplexStr

(ComplexStr) method Capture

Defined as:

method Capture(ComplexStr:D --> Capture:D)

Equivalent to Mu.Capture.

class Failure

From Failure

(Failure) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture if the invocant is a type object or a handled Failure. Otherwise, throws the invocant's exception.

class RatStr

From RatStr

(RatStr) method Capture

Defined as:

method Capture(RatStr:D --> Capture:D)

Equivalent to Mu.Capture.

class Str

From Str

(Str) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

role Blob

From Blob

(Blob) method Capture

Defined as:

method Capture(Blob:D)

Equivalent to calling .List.Capture on the invocant.

class Int

From Int

(Int) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class Version

From Version

(Version) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class Channel

From Channel

(Channel) method Capture

Defined as:

method Capture(Channel:D --> Capture:D)

Equivalent to calling .List.Capture on the invocant.

class Whatever

From Whatever

(Whatever) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class Map

From Map

(Map) method Capture

Defined as:

method Capture(Map:D:)

Returns a Capture where each key, if any, has been converted to a named argument with the same value as it had in the original Map. The returned Capture will not contain any positional arguments.

my $map = Map.new('a' => 2, 'b' => 17);
my $capture = $map.Capture;
my-sub(|$capture);                                # OUTPUT: «2, 17»

sub my-sub(:$a, :$b) {
    say "$a, $b"
}

class Signature

From Signature

(Signature) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class List

From List

(List) method Capture

Defined as:

method Capture(--> Capture:D)

Returns a Capture where each Pair, if any, in the List has been converted to a named argument (with the key of the Pair stringified). All other elements in the List are converted to positional arguments in the order they are found, i.e. the first non pair item in the list becomes the first positional argument, which gets index 0, the second non pair item becomes the second positional argument, getting index 1 etc.

my $list = (7, 5, a => 2, b => 17);
my $capture = $list.Capture;
say $capture.keys;                                # OUTPUT: «(0 1 a b)␤»
my-sub(|$capture);                                # OUTPUT: «7, 5, 2, 17»

sub my-sub($first, $second, :$a, :$b) {
    say "$first, $second, $a, $b"
}

A more advanced example demonstrating the returned Capture being matched against a Signature.

my $list = (7, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «True␤»

$list = (8, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «False␤»

class Supply

From Supply

(Supply) method Capture

Defined as:

method Capture(Supply:D: --> Capture:D)

Equivalent to calling .List.Capture on the invocant.

class Num

From Num

(Num) method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

class Capture

From Capture

(Capture) method Capture

Defined as:

method Capture(Capture:D: --> Capture:D)

Returns itself, i.e. the invocant.

say \(1,2,3, apples => 2).Capture; # OUTPUT: «\(1, 2, 3, :apples(2))␤»

class Mu

From Mu

(Mu) method Capture

Declared as:

method Capture(Mu:D: --> Capture:D)

Returns a Capture with named arguments corresponding to invocant's public attributes:

class Foo {
    has $.foo = 42;
    has $.bar = 70;
    method bar { 'something else' }
}.new.Capture.say; # OUTPUT: «\(:bar("something else"), :foo(42))␤»