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 December 04, 2004
08:49 PM

Sub::Signatures now works with methods

[ #22144 ]

This now works:

package Some::Package;
use Sub::Signatures 'strict';

sub new { bless {} => shift }

sub foo($self, ARRAY $bar) {
    return sprintf "arrayref with %d elements" => scalar @$bar;
}

sub foo($self, HASH $bar) {
    $bar->{this} = 1;
    $bar;
}

It doesn't work with subclassing, though. I think we'll have to add a new items to the import list:

use Sub::Signatures qw/methods/; # 'strict' is optional

I'm unsure of how to handle the special case of methods that can be called as both classes and methods. If it's a class name, it defaults to SCALAR. Otherwise, it defaults to the class name. I think I will have to set it up to ignore the type of the first argument with methods unless the programmer explicitly states it. That seems like a nice compromise.

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.
  • What about lvalue subs? Say I want to do this:
    $obj->foo = $hash_ref;
    I want to make sure that the foo() method only accepts a hash. Would it be defined like this?
    sub foo : method(HASH $x){
       $x->{whatever} = 1;
    }
    I may have the syntax wrong - it's been a while since I played with lvalue subs. But, I think you see what I'm trying to do. Possible?
    • Argh! I hadn't even considered lvalue subs. I'll have to think about them. At the present time I don't see support for them being offered without someone being gracious enough to send a patch :) (after it gets to the CPAN, of course.)