Skip to content

Commit

Permalink
Added helper method Parameter.cool_constant
Browse files Browse the repository at this point in the history
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 bea5199
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/Parameter.pm6
Expand Up @@ -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
}
Expand Down

0 comments on commit bea5199

Please sign in to comment.