Perrin Harkins wrote:[...]
On Tue, 2004-01-20 at 16:17, Stas Bekman wrote:
I now more or less have an idea on how to solve the code usage problem.
Great!
My idea is replace UNIVERSAL::AUTOLOAD with AUTOLOAD for each class that contains objects, so when the method is called on that object it'll do just that:
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html#C_AUTOLOAD_
OK, here it is. Please give it a try:
Index: lib/ModPerl/WrapXS.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/ModPerl/WrapXS.pm,v
retrieving revision 1.64
diff -u -u -r1.64 WrapXS.pm
--- lib/ModPerl/WrapXS.pm 31 Jan 2004 10:06:59 -0000 1.64
+++ lib/ModPerl/WrapXS.pm 9 Feb 2004 18:36:02 -0000
@@ -786,6 +786,16 @@
return keys %$methods;
}+sub avail_modules {
+ my %modules = ();
+ for my $method (keys %$methods) {
+ for my $item ( @{ $methods->{$method} }) {
+ $modules{$item->[MODULE]}++;
+ }
+ }
+ return keys %modules;
+}
+
sub preload_all_modules {
_get_modules() unless $modules;
eval "require $_" for keys %$modules;
Index: src/modules/perl/mod_perl.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.c,v
retrieving revision 1.206
diff -u -u -r1.206 mod_perl.c
--- src/modules/perl/mod_perl.c 10 Jan 2004 05:01:04 -0000 1.206
+++ src/modules/perl/mod_perl.c 9 Feb 2004 18:36:02 -0000
@@ -246,6 +246,10 @@
av_push(GvAV(PL_incgv),
newSVpv(ap_server_root_relative(p, "lib/perl"), 0));
#endif /* MP_COMPAT_1X */
+
+ /* AUTOLOADs */
+ /* XXX: consider adding a config flag not to preload this module */
+ modperl_require_module(aTHX_ "ModPerl::EazyLife", TRUE); if (!modperl_config_apply_PerlRequire(s, scfg, perl, p)) {
exit(1);
--- /dev/null 1969-12-31 16:00:00.000000000 -0800
+++ lib/ModPerl/EazyLife.pm 2004-02-03 08:00:34.000000000 -0800
@@ -0,0 +1,19 @@
+package EazyLife;
+
+use ModPerl::MethodLookup ();
+
+for my $module (ModPerl::MethodLookup::avail_modules()) {
+ *{"$module\::AUTOLOAD"} = sub {
+ my($hint, @modules) =
+ ModPerl::MethodLookup::lookup_method($AUTOLOAD, @_);
+ if (@modules) {
+ eval "require $_" for @modules;
+ goto &$AUTOLOAD;
+ }
+ else {
+ die $hint;
+ }
+ };
+}
+
+1;
______________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
