|Syntactic Confectionery Delight|
OO-style modifiers for 'sub' ?by Gilimanjaro (Hermit)
|on Jan 24, 2003 at 17:10 UTC||Need Help??|
This is my first meditation (well online meditation anyway), so please forgive me if it isn't up to the usual Monk standards, or if it turns out to be total non-sense... (I am after all only a simple scribe)
More and more I am building my Perl applications in a nice an clean OO way, with constructors, inheritance, prototypes, you name it. Lately I'm finding myself repeating the same few lines of code in every single instance method;
And the same with 'ref' negated for each class method. This has become my generic valid invocation checker... I know 'ref' should probably be 'blessed', but my Perl knowlegde may be a bit out of date. For class methods, $self should in fact probably be checked with /\W/, and possibly another check to see if the namespace is defined.
I was wondering if it might make sence to add 'modifiers' to the 'sub' keyword that would indicate to the interpreter to do checks like this... Something like:
The 'method' modifier would setup $SELF automagically for instance. This would 'standardize' the syntax used in method code, while still allowing 'old-fashioned' code.
Maybe I've been working in Java too much, but this kind of run-time checking would greatly enhance my coding experience I think...
Naturally you guys will tell me that Perl 6 has all these things, and I will be shamed for not knowing enough about Perl 6... :)