I’m using MooseX::Declare and methods, which uses MooseX::Method::Signatures. Let’s say I have a class ‘foo’ with a method ‘bar’, and I’ve implemented it like:
class foo {
method bar (Str $str, Bool :$flag = 1) {
# ....
}
}
I now want to write a front-end interface that asks a user what class they want to use, what method on that class they want to use, and then what options to the method they want. I can do the first two things, so let’s say the user has now chosen class foo and method bar.
But how do I find out that method bar takes a string as the first argument, and a flag => bool key value pair that defaults to 1? My code needs to know this so I can then ask the user to supply these things.
First, get the method meta object:
Then, make sure it’s a signaturey method:
Get its signature:
Then look at
$sig‘snamed_paramsandpositional_paramsas detailed in the Parse::Method::Signatures::Sig docs.To find
parsed_signature, I had to look at the source to MooseX::Method::Signatures::Meta::Method… so be wary when you do this.