1 package Maypole::Application;
5 use UNIVERSAL::require;
11 my ( $self, @plugins ) = @_;
12 my $caller = caller(0);
14 push @{"${caller}::ISA"}, $self;
16 foreach (sort @plugins) {
17 if (/^\-Setup$/) { $autosetup++; }
19 *{"$caller\::debug"} = sub { 1 };
20 warn "Debugging enabled";
22 elsif (/^-.*$/) { warn "Unknown flag: $_" }
24 # The plugin caller should be our application class
25 eval "package $caller; require Maypole::Plugin::$_";
26 if ($@) { warn qq(Loading plugin "Maypole::Plugin::$_" failed: $@) }
28 warn "Loaded plugin: Maypole::Plugin::$_" if $caller->debug;
29 unshift @ISA, "Maypole::Plugin::$_";
33 $caller->setup() if $autosetup;
36 if ( $ENV{MOD_PERL} ) {
37 Apache::MVC->require or die "Loading Apache frontend failed: $@";
38 push @ISA, 'Apache::MVC';
41 CGI::Maypole->require or die "Loading CGI frontend failed: $@";
42 push @ISA, 'CGI::Maypole';
49 Maypole::Application - Maypole Universal Frontend
53 use Maypole::Application;
55 use Maypole::Application qw(Config::YAML);
57 use Maypole::Application qw(-Debug Config::YAML -Setup);
59 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
63 This is a universal frontend for mod_perl1, mod_perl2 and CGI.
65 You can omit the Maypole::Plugin:: prefix from plugins.
66 So Maypole::Plugin::Config::YAML becomes Config::YAML.
68 use Maypole::Application qw(Config::YAML);
70 You can also set special flags like -Setup and -Debug.
72 use Maypole::Application qw(-Debug Config::YAML -Setup);
74 The position of plugins and flags in the chain is important,
75 because they are loaded/executed in the same order they appear.
79 use Maypole::Application qw(-Setup);
83 use Maypole::Application;
88 use Maypole::Application qw(-Debug);
92 use Maypole::Application;
97 Sebastian Riedel, C<sri@oook.de>
98 Idea by Marcus Ramberg, C<marcus@thefeed.no>
102 You may distribute this code under the same terms as Perl itself.