Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature introspection API #64

Open
schwern opened this issue Feb 17, 2013 · 5 comments
Open

Signature introspection API #64

schwern opened this issue Feb 17, 2013 · 5 comments

Comments

@schwern
Copy link
Contributor

schwern commented Feb 17, 2013

perl5i has the ability to introspect signatures to ask questions like "how many positional parameters do you take?" This is useful for creating things like loops that now how many elements to iterate at a time.

my @names = ("Joe", "Smith", "Jim", "Dandy", "Jane", "Lane");
@names->foreach( func($fname, $lname) {
    say "Person: $fname $lname";
});

perl5i's signature API is very simple right now. You can ask it for the original signature, a list of parameters, how many positional vs named parameters there are, what the invocant is and if its a method.

Method::Signatures can do that and more. It will fall out of what we need internally for #30 and #31.

The functional requirement is to allow perl5i to use Method::Signatures, but I think its very useful.

@barefootcoder
Copy link
Contributor

I looked at the perl5i stuff a bit, but I'm still not sure how it actually works. So you have code such as:

func foo () { say "foo" }
my $foo = \&foo;

and $foo is then an object which has a signature method. But I'm not sure how we convince the function reference to return the object.

@schwern
Copy link
Contributor Author

schwern commented Feb 17, 2013

That need not be Method::Signature's concern. perl5i can take care of that.

It does it's trick using autobox. In your code below, $foo isn't an object,
it's a code ref. Autoboxing lets us call methods on unblessed references.
Then the reference to signature object mapping is stored in a fieldhash.
See perl5i::2::CODE.

Anyhow, all Method::Signatures needs to provide is the object and maybe the
mapping.
On Feb 17, 2013 5:08 PM, "Buddy Burden" notifications@github.com wrote:

I looked at the perl5i stuff a bit, but I'm still not sure how it actually
works. So you have code such as:

func foo () { say "foo" }
my $foo = &foo;

and $foo is then an object which has a signature method. But I'm not sure
how we convince the function reference to return the object.


Reply to this email directly or view it on GitHubhttps://github.com//issues/64#issuecomment-13681422.

@barefootcoder
Copy link
Contributor

That need not be Method::Signature's concern. perl5i can take care of that.

It does it's trick using autobox.

Oh, I see. Except ... in that case, the signature method is provided on the perl5i side. But the info about the signature is on the MS side. So how does the info get from one side to the other?

@schwern
Copy link
Contributor Author

schwern commented Feb 17, 2013

We'll probably have to provide a method to get the signature for a given
function reference. Method:: Signatures->signature_for(&foo) or something.

@barefootcoder
Copy link
Contributor

Okay, got it now. That should be doable moderatey easily, although (as you say) I think this will be dependent on #31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants