Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2015/04/15

Subroutine Signatures and Multimethods in Perl, Oh My!

This is a question I asked about on Google+ a while ago: How do you have multiple subroutines responding to the same name, distinguished only by the subroutine signature? It isn't yet a part of the experimental "signatures" feature that came in for 5.20 (to my understanding).

Turns out, there's a name for it. Multi-methods.

And it turns out there's a module in CPAN already: Class::Multimethods.

And, like so many very strange, very cool modules you don't know you need until you get there, it was written by Damian Conway.

The way I expect I'd handle it, I'd have each test() version handle the input to get what I need as input, then have an internal subroutine handle the munged input. But then again, I'm not sure. My mind is still blown by this, so I don't really know how to use it.

You'll excuse me; it took several years before I felt confident enough to take on the Schwartzian Transform, much less understand and use it, so I'm very happy to get this, even before knowing where or if I'd use it.

(I don't use unicode in the examples, but think that more people should know about the unicode features in newer Perl.)

No comments:

Post a Comment