CALL-ME
ErrorsCollection

CALL-ME

Synthesised documentation from type/Enumeration type/Callable

From type/Enumeration

See Original text in context

multi method CALL-ME(|)

Returns an Enumeration instance given an enum value.

enum Mass ( mg => 1/1000=> 1/1kg => 1000/1 );
say Mass(1/1000); # OUTPUT: mg

From type/Callable

See Original text in context

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

This method is required for the ( ) postcircumfix operator and the .( ) postcircumfix operator. 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, it has to implement Callable.

class A does Callable {
    submethod CALL-ME(|c){ 'called' }
}
my &a = 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.

class A {
    has @.values;
    submethod CALL-ME(Int $x where 0 <= * < @!values.elems{
        @!values[$x]
    }
}
my $a = A.new: values => [4,5,6,7];
say $a(2); # OUTPUT: «6␤»