1 package Maypole::Application;
5 use UNIVERSAL::require;
10 our $VERSION = '2.05';
13 my ( $self, @plugins ) = @_;
14 my $caller = caller(0);
16 push @{"${caller}::ISA"}, $self;
18 foreach (sort @plugins) {
19 if (/^\-Setup$/) { $autosetup++; }
21 *{"$caller\::debug"} = sub { 1 };
22 warn "Debugging enabled";
24 elsif (/^-.*$/) { warn "Unknown flag: $_" }
26 # The plugin caller should be our application class
27 eval "package $caller; require Maypole::Plugin::$_";
28 if ($@) { warn qq(Loading plugin "Maypole::Plugin::$_" failed: $@) }
30 warn "Loaded plugin: Maypole::Plugin::$_" if $caller->debug;
31 unshift @ISA, "Maypole::Plugin::$_";
36 $caller->config(Maypole::Config->new);
37 $caller->setup() if $autosetup;
40 if ( $ENV{MOD_PERL} ) {
41 Apache::MVC->require or die "Loading Apache frontend failed: $@";
42 push @ISA, 'Apache::MVC';
45 CGI::Maypole->require or die "Loading CGI frontend failed: $@";
46 push @ISA, 'CGI::Maypole';
53 Maypole::Application - Maypole Universal Frontend
57 use Maypole::Application;
59 use Maypole::Application qw(Config::YAML);
61 use Maypole::Application qw(-Debug Config::YAML -Setup);
63 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
67 This is a universal frontend for mod_perl1, mod_perl2 and CGI.
69 You can omit the Maypole::Plugin:: prefix from plugins.
70 So Maypole::Plugin::Config::YAML becomes Config::YAML.
72 use Maypole::Application qw(Config::YAML);
74 You can also set special flags like -Setup and -Debug.
76 use Maypole::Application qw(-Debug Config::YAML -Setup);
78 The position of plugins and flags in the chain is important,
79 because they are loaded/executed in the same order they appear.
83 use Maypole::Application qw(-Setup);
87 use Maypole::Application;
92 use Maypole::Application qw(-Debug);
96 use Maypole::Application;
101 Sebastian Riedel, C<sri@oook.de>
102 Idea by Marcus Ramberg, C<marcus@thefeed.no>
106 You may distribute this code under the same terms as Perl itself.