I've been trying to learn the ins and outs of mod_perl and CGI::Application lately, and I've been puzzling over something. I could use; the advise of more enlightened minds then mine.

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?

#! /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;
Meanwhile in ./lib/menu.pl
sub menu { 'Ouch'; }

In reply to CGI::Application musings by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.