Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

Proposed SelfLoader enhancement -- lexical scope

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


blgl at hagernas

Nov 29, 2006, 3:33 AM

Post #1 of 1 (123 views)
Permalink
Proposed SelfLoader enhancement -- lexical scope

It would be nice if selfloaded subs could see module lexical
declarations, so I thought up a way to do it.

1. The cache of sub definitions is extended to include the name of
the package from whose DATA filehandle each sub was loaded.
2. At eval time, the origin package is checked to see if it defines
a sub named SelfLoader_eval. If it does, this sub is called
to evaluate the sub definition. Otherwise, SelfLoader's internal
code is used.
3. To use the new mechanism, a client module defines a SelfLoader_eval
sub at an appropriate location in its file. Example below.

-------- begin MyPackage.pm --------
package MyPackage;
use SelfLoader;

# These variables are visible to selfloaded subs.
my($mineral,@vegetable,%animal);

sub SelfLoader_eval
{
eval($_[0]);
}

# These variables are NOT visible to selfloaded subs.
my($this,@that,%other);

# Other sub definitions go here.

__DATA__

# Selfloaded sub definitions go here.

-------- end MyPackage.pm --------

So, should I go ahead and write documentation and test cases for this?


/Bo Lindbergh
Attachments: SelfLoader.pm.diff (4.43 KB)

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.