1 package Maypole::Application;
6 use UNIVERSAL::require;
10 our $VERSION = '2.11';
13 shift; # not interested in this - we manipulate the caller's @ISA directly
15 my $caller = caller(0);
17 my $frontend = 'Apache::MVC' if $ENV{MOD_PERL};
19 $frontend = 'Maypole::HTTPD::Frontend' if $ENV{MAYPOLE_HTTPD};
22 if ( grep { /^MasonX$/ } @plugins )
25 @plugins = grep { ! /^MasonX$/ } @plugins;
26 $frontend = 'MasonX::Maypole';
29 $frontend ||= 'CGI::Maypole';
31 $frontend->require or die "Loading $frontend frontend failed: $@";
39 if (/^\-Setup$/) { $autosetup++; }
40 elsif (/^\-Init$/) { $autoinit++ }
41 elsif (/^\-Debug(\d*)$/) {
44 *{"$caller\::debug"} = sub { $d };
45 warn "Debugging (level $d) enabled for $caller";
47 elsif (/^-.*$/) { warn "Unknown flag: $_" }
49 my $plugin = "Maypole::Plugin::$_";
50 if ($plugin->require) {
51 push @plugin_modules, "Maypole::Plugin::$_";
52 warn "Loaded plugin: $plugin for $caller"
53 if $caller->can('debug') && $caller->debug;
55 die qq(Loading plugin "$plugin" for $caller failed: )
56 . $UNIVERSAL::require::ERROR;
62 push @{"${caller}::ISA"}, @plugin_modules, $frontend;
63 $caller->config(Maypole::Config->new);
64 $caller->config->masonx({}) if $masonx;
65 $caller->setup() if $autosetup;
66 $caller->init() if $autosetup && $autoinit;
73 Maypole::Application - Universal Maypole Frontend
77 use Maypole::Application;
79 use Maypole::Application qw(Config::YAML);
81 use Maypole::Application qw(-Debug Config::YAML -Setup);
83 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
85 use Maypole::Application qw(-Debug2 MasonX AutoUntaint);
89 This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI.
91 Automatically determines the appropriate frontend for your environment (unless
92 you want to use L<MasonX::Maypole>, in which case include C<MasonX> in the
95 Loads plugins supplied in the C<use> statement.
97 Responds to flags supplied in the C<use> statement.
99 Initializes the application's configuration object.
101 You can omit the Maypole::Plugin:: prefix from plugins. So
102 Maypole::Plugin::Config::YAML becomes Config::YAML.
104 use Maypole::Application qw(Config::YAML);
106 You can also set special flags like -Setup, -Debug and -Init.
108 use Maypole::Application qw(-Debug Config::YAML -Setup);
110 The position of plugins in the chain is important, because they are
111 loaded/executed in the same order they appear.
115 Under mod_perl (1 or 2), selects L<Apache::MVC>.
117 Otherwise, selects L<CGI::Maypole>.
119 If C<MasonX> is specified, sets L<MasonX::Maypole> as the frontend. This
120 currently also requires a mod_perl environment.
128 use Maypole::Application qw(-Setup);
132 use Maypole::Application;
135 Note that no options are passed to C<setup()>. You must ensure that the
136 required model config parameters are set in C<MyApp-E<gt>config>. See
137 L<Maypole::Config> for more information.
141 use Maypole::Application qw(-Setup -Init);
145 use Maypole::Application;
149 Note that the C<-Setup> flag is required for the C<-Init> flag to work.
151 In persistent environments (e.g. C<mod_perl>), it is useful to call C<init>
152 once in the parent server, rather than at the beginning of the first request
153 to each child server, in order to share the view code loaded during C<init>.
154 Note that you must supply all the config data to your app before calling
155 C<setup> and C<init>, probably by using one of the C<Maypole::Plugin::Config::*>
160 use Maypole::Application qw(-Debug);
164 use Maypole::Application;
167 You can specify a higher debug level by saying C<-Debug2> etc.
173 Sebastian Riedel, C<sri@oook.de>
174 Idea by Marcus Ramberg, C<marcus@thefeed.no>
178 You may distribute this code under the same terms as Perl itself.