role Callable

Invocable code object

role Callable { ... }

Role for objects which support calling them. It's used in Block, Routine, Sub, Method, Submethod and Macro types.

Callables can be stored in &-sigiled containers, the default type constraint of such a container is Callable.

my &a = {;}# Empty block needs a semicolon 
my &b = -> {};
my &c = sub () {};
sub foo() {};
my &d = &foo;

Methods

method CALL-ME

method CALL-ME(Callable:D $self: |arguments)

This method is required for postfix:«( )» and postfix:«.( )». It's what makes an object actually call-able and needs to be overloaded to let a given object act like a routine. If the object needs to be stored in a &-sigiled container, is has to implement Callable.

class A does Callable {
    submethod CALL-ME(|c){ 'called' }
}
my &a = A;
say a(); # OUTPUT: «called␤»

method Capture

Defined as:

method Capture()

Throws X::Cannot::Capture.

Type Graph

Type relations for Callable
perl6-type-graph Callable Callable Mu Mu Any Any Any->Mu ForeignCode ForeignCode ForeignCode->Callable ForeignCode->Any Code Code Code->Callable Code->Any Block Block Block->Code WhateverCode WhateverCode WhateverCode->Code Routine Routine Routine->Block Method Method Method->Routine Macro Macro Macro->Routine Submethod Submethod Submethod->Routine Sub Sub Sub->Routine Regex Regex Regex->Method

Expand above chart