#! /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;