1 package Maypole::Application;
5 use UNIVERSAL::require;
12 shift; # not interested in this - we manipulate the caller's @ISA directly
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 (/^\-Init$/) { $autoinit++ }
37 elsif (/^\-Debug(\d*)$/) {
40 *{"$caller\::debug"} = sub { $d };
41 warn "Debugging (level $d) enabled for $caller";
43 elsif (/^-.*$/) { warn "Unknown flag: $_" }
45 my $plugin = "Maypole::Plugin::$_";
46 if ($plugin->require) {
47 push @plugin_modules, "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, $frontend;
59 $caller->config(Maypole::Config->new);
60 $caller->config->masonx({}) if $masonx;
61 $caller->setup() if $autosetup;
62 $caller->init() if $autosetup && $autoinit;
69 Maypole::Application - Universal Maypole Frontend
73 use Maypole::Application;
75 use Maypole::Application qw(Config::YAML);
77 use Maypole::Application qw(-Debug Config::YAML -Setup);
79 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
81 use Maypole::Application qw(-Debug2 MasonX AutoUntaint);
85 This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI.
87 You can omit the Maypole::Plugin:: prefix from plugins.
88 So Maypole::Plugin::Config::YAML becomes Config::YAML.
90 use Maypole::Application qw(Config::YAML);
92 You can also set special flags like -Setup, -Debug and -Init.
94 use Maypole::Application qw(-Debug Config::YAML -Setup);
96 The position of plugins and flags in the chain is important,
97 because they are loaded/executed in the same order they appear.
101 use Maypole::Application qw(-Setup);
105 use Maypole::Application;
108 Note that no options are passed to C<setup()>. You must ensure that the
109 required model config parameters are set in C<MyApp-E<gt>config>. See
110 L<Maypole::Config> for more information.
114 use Maypole::Application qw(-Setup -Init);
118 use Maypole::Application;
122 Note that the C<-Setup> flag is required for the C<-Init> flag to work.
124 In persistent environments (e.g. C<mod_perl>), it is useful to call C<init>
125 once in the parent server, rather than at the beginning of the first request
126 to each child server, in order to share the view code loaded during C<init>.
127 Note that you must supply all the config data to your app before calling
128 C<setup> and C<init>, probably by using one of the C<Maypole::Plugin::Config::*>
133 use Maypole::Application qw(-Debug);
137 use Maypole::Application;
140 You can specify a higher debug level by saying C<-Debug2> etc.
144 Sebastian Riedel, C<sri@oook.de>
145 Idea by Marcus Ramberg, C<marcus@thefeed.no>
149 You may distribute this code under the same terms as Perl itself.