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 warn "Loaded plugin: $plugin for $caller"
48 if $caller->can('debug') && $caller->debug;
50 die qq(Loading plugin "$plugin" for $caller failed: )
51 . $UNIVERSAL::require::ERROR;
57 push @{"${caller}::ISA"}, @plugin_modules, $class;
58 $caller->config(Maypole::Config->new);
59 $caller->config->masonx({}) if $masonx;
60 $caller->setup() if $autosetup;
67 Maypole::Application - Universal Maypole Frontend
71 use Maypole::Application;
73 use Maypole::Application qw(Config::YAML);
75 use Maypole::Application qw(-Debug Config::YAML -Setup);
77 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
79 use Maypole::Application qw(-Debug2 MasonX AutoUntaint);
83 This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI.
85 You can omit the Maypole::Plugin:: prefix from plugins.
86 So Maypole::Plugin::Config::YAML becomes Config::YAML.
88 use Maypole::Application qw(Config::YAML);
90 You can also set special flags like -Setup and -Debug.
92 use Maypole::Application qw(-Debug Config::YAML -Setup);
94 The position of plugins and flags in the chain is important,
95 because they are loaded/executed in the same order they appear.
99 use Maypole::Application qw(-Setup);
103 use Maypole::Application;
106 Note that no options are passed to C<setup()>. You must ensure that the
107 required model config parameters are set in C<MyApp-E<gt>config>. See
108 L<Maypole::Config> for more information.
112 use Maypole::Application qw(-Debug);
116 use Maypole::Application;
119 You can specify a higher debug level by saying C<-Debug2> etc.
123 Sebastian Riedel, C<sri@oook.de>
124 Idea by Marcus Ramberg, C<marcus@thefeed.no>
128 You may distribute this code under the same terms as Perl itself.