[prev in list] [next in list] [prev in thread] [next in thread]
List: perl5-porters
Subject: auto-declaring subs
From: Ashley Winters <jql () accessone ! com>
Date: 2001-04-15 21:35:43
[Download RAW message or body]
Hello all,
I was trying to implement some rather sick voodoo when I encountered a
snag.
# sick voodoo
sub add : args(bar, baz) {
frob(bar, baz);
}
That works using an lvalue AUTOLOAD which recognizes the named arguments
based on caller() and returns lvalue @_ elements thanks to @DB::args.
The problem is that bar and baz are converted to strings before the use
attributes call has a chance to introduce them as lvalue subs.
However, these work beautifully:
# separate declaration
sub foo : args(bar, baz);
sub foo {
print bar . baz;
}
# use parens
sub blurfl : args(baz, bar) {
print baz() . bar();
}
foo("Hello ", "World!");
blurfl("Hello ", "World!");
Would it be reasonable to have the parser stop and declare the sub before
parsing the block? Can sub foo (proto) : attributes {} be made equivalent
to sub foo (proto) : attributes; sub foo {}? For now, I can live with
the work-arounds.
And on a side note, is @DB::args threadsafe? It seems like running
caller() from multiple threads would cause a race-condition on reading
@DB::args.
Thanks,
Ashley Winters
--
Trust me, you don't wanna know how I implemented :virtual.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic