Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
My plan is to use AUTOLOAD to ... well autoload C::A's run_modes. I put a file in a known location (say ./lib/menu.pl) and &lazy_loader requires it. I guess this kinda goes against the principle of C::A put it seems like a good idea. The application will have dozens of run modes and I'm just to lazy to keep filling out the dispatch table. This works OK, but I can't help but to think I missing something. Is this a bad idea?
Also, mod_perl seems a little buggy, in as much as every once in a while (when I'm making changes in one of the required .pl files) it randomly fails with 'cant find Foobar.pm in @INC' but Foobar is there and @INC is correct. I restart the server and everything works. I can't reproduce it, and I don't see any pattern, but it happens fairly frequently.
Any suggestions, advise, dope slaps?
Meanwhile in ./lib/menu.pl#! /usr/bin/perl -w package Foobar; use strict; use base 'CGI::Application'; use Apache::Reload; sub setup { my $self = shift; $self->load_run_modes(); $self->start_mode('menu'); $self->run_modes("AUTOLOAD"=>\&lazy_loader); } # Add .pl files in ./lib for each run mode # This silly little sub (along with lazy_loader) will find and require + them. sub load_run_modes { my $self = shift; foreach (< ./lib/.*pl >) { /.*lib\/(\w+).pl/; require $_; } } # This is just to avoid having to add sub's to run_modes # see load_run_modes sub lazy_loader { no strict 'refs'; &{$_[1]}; use strict 'refs'; } 1;
sub menu { 'Ouch'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Application musings
by ihb (Deacon) on May 30, 2005 at 00:36 UTC | |
by cees (Curate) on May 30, 2005 at 02:03 UTC | |
|
Re: CGI::Application musings
by cees (Curate) on May 30, 2005 at 01:49 UTC | |
|
Re: CGI::Application musings
by dragonchild (Archbishop) on May 30, 2005 at 01:52 UTC |