wanna_code_perl has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I'm going to try my best not to pose an XY Problem here, but I'm having a tough time coming up with a succinct explanation. Here goes nothing.
I'm working on initialization code for a complex system, with many user- (programmer-)defined levels of nested data structures. The data structure is trivial for a computer to traverse, but making it comprehensible to the programmer is another story. Further, trusting the programmer to initialize it correctly using pure Perl variable syntax would ask for a lot of artificial housekeeping and invite errors, or worse, ambiguity. Fortunately, implementing just a few new simple keywords solves all of these problems (many of them right at compile time) with simple, concise syntax, but having those subs operate on anything less than a file-scoped variable has eluded me. Here's what I've tried/considered:
Here's the sort of syntax I'm aiming for:
use The::Package; # sub my_generator(&) is exported by The::Package my $complex_result = my_generator { foo 'bar'; takes_coderef { ... }; }; foo 'baz'; # Should not affect $complex_result. # Ideally, should croak, or not even compile.
I hope this question makes sense, and has a solution which is much simpler than my explanation. The short, short version of my question is: is there any way to implement prototyped subs that will automatically gain access to a given scalar/ref/object/alias to the same without explicitly passing it in to every call or using the $arrow->notation?)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making lexically-scoped ref available to non-OO subs in another package
by tobyink (Canon) on Jul 12, 2013 at 12:53 UTC | |
by wanna_code_perl (Friar) on Jul 12, 2013 at 13:30 UTC | |
by tobyink (Canon) on Jul 13, 2013 at 07:35 UTC | |
|
Re: Making lexically-scoped ref available to non-OO subs in another package
by Anonymous Monk on Jul 12, 2013 at 13:25 UTC |