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 ]

gav (2710)

gav
  (email not shown publicly)
http://www.estey.com/
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Monday September 08, 2003
11:04 AM

coding standards

[ #14583 ]

I had a crazy idea in the middle of the night. Can I be a code nazi and enforce my standards? I use a leading underscore for private methods and a double underscore for helper subs. I came up with this:

use Hook::WrapSub qw( wrap_subs );

sub init {
    my $wrap = sub {
        if ($_[0] =~ /^__/ && ref($_[1]) eq __PACKAGE__) {
            die "$_[0]: I'm just a helper sub, not a method call!\n";
        }
        unless((caller(2))[0] eq __PACKAGE__) {
            die "$_[0]: I'm a private sub, hands off!\n";
        }
    };
    while (my ($sym, $glob) = each %{__PACKAGE__ . '::'}) {
        if ($sym =~ /^_{1,2}/ && defined *{$glob}{CODE}) {
            wrap_subs(sub { $wrap->($sym, @_) }, __PACKAGE__.'::'.$sym);
        }
    }
}

I'm not sure if I like this, but I'm happy I figured out how to make it work :)

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.