I can see from my original node that I (once again) was not terribly clear. The intent of this idea was to ensure that I had a general purpose module that I could point to any namespace and it would recursively travel through the directories (via File::Find or File::Find::Rule) and prepare those subroutines as I outlined above. Thus, I wouldn't have to change code in any of the classes found.
Further, by just adopting the syntax you listed in Re: The costs of packages, I think I might get exporting to work, also. What follows is a mish-mash of pseudo-code and Perl:
package Class::WhenNeeded; use File::Find; sub import { my ($class, $top_package, $no_top_level) = @_; my @dirs = map { find_top_level_dir($_, $top_package) } @INC; foreach my $dir (@dirs) { find({ wanted => \&create_package_sub($no_top_level), preprocess => \&perl_packages, }, $dir); } } sub create_package_sub { my $strip_top_level = shift; my $module = make_module_name($File::Find::name, $strip_top_ +level); my $call_pack = (caller(1))[1]; if (defined &{$module}) { require Carp; Carp::croak "Function $module already defined"; } *{$module} = sub { undef *{$module}; eval <<" END_EVAL"; package $call_pack; use $module; # export goes to calling package? END_EVAL if ($@) { require Carp; Carp::croak "Could not load module: $module"; } return $module; } }
Hopefully that clears things up.
Cheers,
Ovid
New address of my CGI Course.
In reply to Re: Re: DWIM: autoloading classes
by Ovid
in thread DWIM: autoloading classes
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |