1 package Maypole::Application;
5 use UNIVERSAL::require;
10 our $VERSION = '2.09';
13 my ( $class, @plugins ) = @_;
14 my $caller = caller(0);
16 my $frontend = 'Apache::MVC' if $ENV{MOD_PERL};
19 if ( grep { /^MasonX$/ } @plugins )
22 @plugins = grep { ! /^MasonX$/ } @plugins;
23 $frontend = 'MasonX::Maypole';
26 $frontend ||= 'CGI::Maypole';
28 $frontend->require or die "Loading $frontend frontend failed: $@";
35 if (/^\-Setup$/) { $autosetup++; }
36 elsif (/^\-Debug(\d*)$/) {
39 *{"$caller\::debug"} = sub { $d };
40 warn "Debugging (level $d) enabled for $caller";
42 elsif (/^-.*$/) { warn "Unknown flag: $_" }
44 my $plugin = "Maypole::Plugin::$_";
45 if ($plugin->require) {
46 push @plugin_modules, "Maypole::Plugin::$_";
47 unshift @ISA, "Maypole::Plugin::$_";
48 warn "Loaded plugin: $plugin for $caller"
49 if $caller->can('debug') && $caller->debug;
51 die qq(Loading plugin "$plugin" for $caller failed: )
52 . $UNIVERSAL::require::ERROR;
58 push @{"${caller}::ISA"}, @plugin_modules, $class;
59 $caller->config(Maypole::Config->new);
60 $caller->config->masonx({}) if $masonx;
61 $caller->setup() if $autosetup;
68 Maypole::Application - Universal Maypole Frontend
72 use Maypole::Application;
74 use Maypole::Application qw(Config::YAML);
76 use Maypole::Application qw(-Debug Config::YAML -Setup);
78 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
80 use Maypole::Application qw(-Debug2 MasonX AutoUntaint);
84 This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI.
86 You can omit the Maypole::Plugin:: prefix from plugins.
87 So Maypole::Plugin::Config::YAML becomes Config::YAML.
89 use Maypole::Application qw(Config::YAML);
91 You can also set special flags like -Setup and -Debug.
93 use Maypole::Application qw(-Debug Config::YAML -Setup);
95 The position of plugins and flags in the chain is important,
96 because they are loaded/executed in the same order they appear.
100 use Maypole::Application qw(-Setup);
104 use Maypole::Application;
107 Note that no options are passed to C<setup()>. You must ensure that the
108 required model config parameters are set in C<MyApp-E<gt>config>. See
109 L<Maypole::Config> for more information.
113 use Maypole::Application qw(-Debug);
117 use Maypole::Application;
120 You can specify a higher debug level by saying C<-Debug2> etc.
124 Sebastian Riedel, C<sri@oook.de>
125 Idea by Marcus Ramberg, C<marcus@thefeed.no>
129 You may distribute this code under the same terms as Perl itself.