Skip to content
Permalink
Browse files

Added helper method Parameter.cool_constant

Not intended to be used outside of the core.  Returns the Cool value of
a Parameter if it is a Cool constant.  Otherwise returns Nil  E.g.:

    sub a("foo") { }; dd &a.signature.params[0].cool_constant;  # "foo"
    sub b($foo ) { }; dd &a.signature.params[0].cool_constant;  # Nil
  • Loading branch information...
lizmat committed Mar 22, 2019
1 parent 2f6e5fd commit bea51993420642800af4bc3b5b08ec60e97625ce
Showing with 9 additions and 0 deletions.
  1. +9 −0 src/core/Parameter.pm6
@@ -630,6 +630,15 @@ my class Parameter { # declared in BOOTSTRAP
$perl ~ $rest;
}

# return the cool constant if the post_constraint is a single Cool constant
method cool_constant() {
nqp::not_i(nqp::isnull(@!post_constraints))
&& nqp::elems(@!post_constraints) == 1
&& nqp::istype((my \value := nqp::atpos(@!post_constraints,0)),Cool)
?? value
!! Nil
}

method sub_signature(Parameter:D:) {
nqp::isnull($!sub_signature) ?? Any !! $!sub_signature
}

0 comments on commit bea5199

Please sign in to comment.
You can’t perform that action at this time.