Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday September 25, 2004
01:10 PM

Naive Signatures

[ #21047 ]

Naive signature processing for Perl is fairly simple:

package Sub::Signatures;
use Filter::Simple;

FILTER_ONLY
    code => sub {
        s <
            sub\s*(\w+)\s*\(([^)]+)\)[^{]*{
        ><sub $1 \{ my ($2) = \@_;>gx;
    };

1;

And using it:

use Sub::Signatures;

sub foo($one, $two, $three) {
    return join ',' => $one, $two, $three;
}

Of course, that doesn't allow signatures on anonymous subs, it does no type checking or validating arguments lists in the actual sub, but it works. Maybe Sub::Overload will become a reality after all.

I should add that writing tests for source filters is very, very hard. First, having source filters generate valid code is difficult. Second, if they do generate valid code, it still might not perform as expected. In your filter block, it's very helpful to add a "print $_" as the last line of the filter subroutine. This will print out the resulting code and make it easier to see what your filter is actually doing.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.