in reply to Possible Stupid Perl Trick - Importing method into object class?
Sounds like you might need a smart AUTOLOAD. Consider a scenario where you have a registry of "process functions" on disk, where the registry is a flat file database with pairs of "function-name, filename" as tuples. When AUTOLOAD is triggered, it scans this registry to locate the file that corresponds with a process function. When it finds one, it loads the file into a string, then evals it (as a sub definition) into the dataset's namespace.
This approach would let you (or others) write new process functions in files external to your main body of code. For extra credit, you could provide an option in your main script to use a different, "debug" registry that you would use for debugging new functions.
Here's an untested fragment, pieced together from pages 468-471 of the Cookbook.
Good lord, I just used a goto.sub AUTOLOAD { my $self = shift; my $attr = $AUTOLOAD; $attr =~ s/.*:://; # open the registry, search for $attr, # open assocated filename and load the # contents into $sub no strict 'refs'; *$attr = eval $sub; goto &$attr; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Possible Stupid Perl Trick - Importing method into object class?
by dragonchild (Archbishop) on Dec 07, 2001 at 22:48 UTC | |
|
Re: Re: Possible Stupid Perl Trick - Importing method into object class?
by dmmiller2k (Chaplain) on Dec 07, 2001 at 23:55 UTC | |
|
Re: Re: Possible Stupid Perl Trick - Importing method into object class?
by Masem (Monsignor) on Dec 07, 2001 at 23:05 UTC | |
by dws (Chancellor) on Dec 08, 2001 at 00:11 UTC |