Open schwern opened 11 years ago
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.
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/schwern/method-signatures/issues/64#issuecomment-13681422.
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?
We'll probably have to provide a method to get the signature for a given function reference. Method:: Signatures->signature_for(&foo) or something.
Okay, got it now. That should be doable moderatey easily, although (as you say) I think this will be dependent on #31.
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.
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.