One of my favorite hacks in Perl Hacks shows how to declare the
:Method attribute so you don't have to type
my $self = shift; anymore. There are lots of ways to do that, but my approach was to avoid source filters (yay). The book goes into more detail, but effectively the trick allows you to declare any other parameter while avoiding most drawbacks of source filters.
Damian correctly pointed out that my technique does have the limitation of not always respecting the lexical compiling environment of the methods.
Today I figured out another approach that only handles invocants, but is
strict safe. That is, now you can write:
my ($class, %args) = @_;
bless \%args, $class;
Of course, you can also use
o or just about any other allowed identifier.
What's the trick? I originally thought
@DB::args would work, but if you take something off of the stack, it's just gone and so the really clever trampoline trick wouldn't do it. Now it only works with versions of
Scalar::Util released this millennium.
Still, I don't really mind that syntax at all.