role Callable
Invocable code object
1 | Methods |
1.1 | method CALL-ME |
1.2 | method Capture |
2 | Type Graph |
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 = ; # Empty block needs a semicolonmy = -> ;my = sub () ;sub foo() ;my = ;
Methods
method CALL-ME
method CALL-ME(Callable : |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.
does Callablemy = A;say a(); # OUTPUT: «called»
Applying the Callable
role is not a requirement to make an object callable; if a class simply wants to add subroutine-like semantics in a regular scalar container, the submethod CALL-ME
can be used for that.
my = A.new: values => [4,5,6,7]say (2); # OUTPUT: «6»
method Capture
Defined as:
method Capture()
Throws X::Cannot::Capture
.