1 package Maypole::Application;
5 use UNIVERSAL::require;
10 our $VERSION = '2.11';
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: $@";
29 # inheritance may already be set up in a multi-app mod_perl environment
30 push @ISA, $frontend unless __PACKAGE__->isa( $frontend );
37 if (/^\-Setup$/) { $autosetup++; }
38 elsif (/^\-Init$/) { $autoinit++ }
39 elsif (/^\-Debug(\d*)$/) {
42 *{"$caller\::debug"} = sub { $d };
43 warn "Debugging (level $d) enabled for $caller";
45 elsif (/^-.*$/) { warn "Unknown flag: $_" }
47 my $plugin = "Maypole::Plugin::$_";
48 if ($plugin->require) {
49 push @plugin_modules, "Maypole::Plugin::$_";
50 warn "Loaded plugin: $plugin for $caller"
51 if $caller->can('debug') && $caller->debug;
53 die qq(Loading plugin "$plugin" for $caller failed: )
54 . $UNIVERSAL::require::ERROR;
60 push @{"${caller}::ISA"}, @plugin_modules, $class;
61 $caller->config(Maypole::Config->new);
62 $caller->config->masonx({}) if $masonx;
63 $caller->setup() if $autosetup;
64 $caller->init() if $autosetup && $autoinit;
71 Maypole::Application - Universal Maypole Frontend
75 use Maypole::Application;
77 use Maypole::Application qw(Config::YAML);
79 use Maypole::Application qw(-Debug Config::YAML -Setup);
81 use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
83 use Maypole::Application qw(-Debug2 MasonX AutoUntaint);
87 This is a universal frontend for mod_perl1, mod_perl2, HTML::Mason and CGI.
89 You can omit the Maypole::Plugin:: prefix from plugins.
90 So Maypole::Plugin::Config::YAML becomes Config::YAML.
92 use Maypole::Application qw(Config::YAML);
94 You can also set special flags like -Setup, -Debug and -Init.
96 use Maypole::Application qw(-Debug Config::YAML -Setup);
98 The position of plugins and flags in the chain is important,
99 because they are loaded/executed in the same order they appear.
103 use Maypole::Application qw(-Setup);
107 use Maypole::Application;
110 Note that no options are passed to C<setup()>. You must ensure that the
111 required model config parameters are set in C<MyApp-E<gt>config>. See
112 L<Maypole::Config> for more information.
116 use Maypole::Application qw(-Setup -Init);
120 use Maypole::Application;
124 Note that the C<-Setup> flag is required for the C<-Init> flag to work.
126 In persistent environments (e.g. C<mod_perl>), it is useful to call C<init>
127 once in the parent server, rather than at the beginning of the first request
128 to each child server, in order to share the view code loaded during C<init>.
129 Note that you must supply all the config data to your app before calling
130 C<setup> and C<init>, probably by using one of the C<Maypole::Plugin::Config::*>
135 use Maypole::Application qw(-Debug);
139 use Maypole::Application;
142 You can specify a higher debug level by saying C<-Debug2> etc.
146 Sebastian Riedel, C<sri@oook.de>
147 Idea by Marcus Ramberg, C<marcus@thefeed.no>
151 You may distribute this code under the same terms as Perl itself.