method lookup
1 | class Metamodel::ClassHOW |
1.1 | (Metamodel::ClassHOW) method lookup |
2 | role Metamodel::MethodContainer |
2.1 | (Metamodel::MethodContainer) method lookup |
Documentation for method lookup
assembled from the following types:
class Metamodel::ClassHOW
From Metamodel::ClassHOW
(Metamodel::ClassHOW) method lookup
method lookup(Metamodel::ClassHOW: , --> Method)
Returns the first matching Method with the provided name. If no method was found, returns a VM-specific sentinel value (typically a low-level NULL value) that can be tested for with a test for definedness. It is potentially faster than .^can
but does not provide a full list of all candidates.
say Str.^lookup('Int').perl; # OUTPUT: «method Int (Str:D $: *%_) { #`(Method|39910024) ... }»for <upper-case uc># OUTPUT:# method `upper-case` not found# FOO
role Metamodel::MethodContainer
From Metamodel::MethodContainer
(Metamodel::MethodContainer) method lookup
method lookup(Metamodel::MethodContainer: , --> Method)
Returns the first matching method object of the provided $name
or (Mu)
if no method object was found. The search for a matching method object is done by following the mro of $obj
. Note that lookup
is supposed to be used for introspection, if you're after something which can be invoked you probably want to use find_method instead.
say 2.5.^lookup("sqrt").perl: # OUTPUT: «method sqrt (Rat $: *%_) ...»say Str.^lookup("BUILD").perl; # OUTPUT: «submethod BUILD (Str $: :$value = "", *%_ --> Nil) ...»say Int.^lookup("does-not-exist"); # OUTPUT: «(Mu)»
The difference between find_method
and lookup
are that find_method
will use a default candidate for parametric roles, whereas lookup
throws an exception in this case, and that find_method
honors FALLBACK
methods, which lookup
does not.