Personally, I never really cared about fancy prototype handling. I just:

my ($this, $a, $b) = @_;

in my code. When doing named params, I will normally do something like %h and then immediately convert then into specific vars.

My reason for posting was I saw your example:

sub convert (:$from, :$to, :$thing) { ... }

It occurred to me that it would be rather easy to support such a thing WIHTOUT sourcefilters thanks to the prototype function.

There are dozens of potential impls. using prototype and I will leave that as an excersize to the readers. But, I don't think I have ever seen a module that does that without source filters. Then again, I haven't looked very hard.

Update: Working on an example of said package.

Update: Here is a quicky that I through together. I have to go home, so I can't spend too much time on this, but I can see why no one has done this before. The code I wrote is:

package Signatures; sub import { no warnings; no strict; my $package = caller; for (keys %{ $package . '::' }) { next unless exists &{ $package . "::$_" }; my $sub = \ &{ $package . "::$_" }; next unless my $proto = prototype $sub; *{ $package . "::$_" } = eval qq { sub { package $package; local ($proto) = \@_; \$sub->() } } } }

Before you kill me, please understand that this was written in 10 minutes and is not intended to be used by anyone. That is why there is no "use strict" and "use warnings", etc. :-) There were several major problems I encountered.

Anyway, here is the code I was able to run. It does work, but I didn't really test this mess.

#!perl -l foo("aaaa", "bbb"); sub foo ($a, $b) { print $a; print $b } use Signatures;

Well, it was an interesting idea, but I don't know if it can really go anywhere. I'll think more about it tonight.

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

In reply to Re: Your named arguments by TedYoung
in thread Your named arguments by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.