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 :)