X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FApplication.pm;h=ae95bb7ee3447df5524c2925adbc7b193d4c0bdc;hb=1ec67be9e8b738cbd2a523523af3bd7e61f98480;hp=38b1ec569ee62c46fe87b44cc2e0d86c3a6de04f;hpb=db03564d2a397a9c092d65fd790ccecde9c55d92;p=maypole.git diff --git a/lib/Maypole/Application.pm b/lib/Maypole/Application.pm index 38b1ec5..ae95bb7 100644 --- a/lib/Maypole/Application.pm +++ b/lib/Maypole/Application.pm @@ -2,6 +2,7 @@ package Maypole::Application; use strict; use warnings; + use UNIVERSAL::require; use Maypole; use Maypole::Config; @@ -15,6 +16,8 @@ sub import { my $frontend = 'Apache::MVC' if $ENV{MOD_PERL}; + $frontend = 'Maypole::HTTPD::Frontend' if $ENV{MAYPOLE_HTTPD}; + my $masonx; if ( grep { /^MasonX$/ } @plugins ) { @@ -30,30 +33,31 @@ sub import { my $autosetup=0; my $autoinit=0; my @plugin_modules; + + foreach (@plugins) { - foreach (@plugins) { - if (/^\-Setup$/) { $autosetup++; } - elsif (/^\-Init$/) { $autoinit++ } - elsif (/^\-Debug(\d*)$/) { - my $d = $1 || 1; - no strict 'refs'; - *{"$caller\::debug"} = sub { $d }; - warn "Debugging (level $d) enabled for $caller"; - } - elsif (/^-.*$/) { warn "Unknown flag: $_" } - else { - my $plugin = "Maypole::Plugin::$_"; - if ($plugin->require) { - push @plugin_modules, "Maypole::Plugin::$_"; - warn "Loaded plugin: $plugin for $caller" - if $caller->can('debug') && $caller->debug; - } else { - die qq(Loading plugin "$plugin" for $caller failed: ) - . $UNIVERSAL::require::ERROR; - } + if (/^\-Setup$/) { $autosetup++; } + elsif (/^\-Init$/) { $autoinit++ } + elsif (/^\-Debug(\d*)$/) { + my $d = $1 || 1; + no strict 'refs'; + *{"$caller\::debug"} = sub { $d }; + warn "Debugging (level $d) enabled for $caller"; + } + elsif (/^-.*$/) { warn "Unknown flag: $_" } + else { + my $plugin = "Maypole::Plugin::$_"; + if ($plugin->require) { + push @plugin_modules, "Maypole::Plugin::$_"; + warn "Loaded plugin: $plugin for $caller" + if $caller->can('debug') && $caller->debug; + } else { + die qq(Loading plugin "$plugin" for $caller failed: ) + . $UNIVERSAL::require::ERROR; } } } + no strict 'refs'; push @{"${caller}::ISA"}, @plugin_modules, $frontend; $caller->config(Maypole::Config->new); @@ -164,49 +168,6 @@ You can specify a higher debug level by saying C<-Debug2> etc. =back -=head1 BeerDB - -The canonical example used in the Maypole documentation is the beer database, -which starts like this: - - package BeerDB; - use strict; - use warnings; - - # choose a frontend, initialise the config object, and load a plugin - use Maypole::Application qw/Relationship/; - - # get the empty config object created by Maypole::Application - my $config = __PACKAGE__->config; - - # basic settings - $config->uri_base("http://localhost/beerdb"); - $config->template_root("/path/to/templates"); - $config->rows_per_page(10); - $config->display_tables([qw[beer brewery pub style]]); - - # table relationships - $config->relationships([ - "a brewery produces beers", - "a style defines beers", - "a pub has beers on handpumps", - ]); - - # validation - BeerDB::Brewery->untaint_columns( printable => [qw/name notes url/] ); - BeerDB::Pub->untaint_columns( printable => [qw/name notes url/] ); - BeerDB::Style->untaint_columns( printable => [qw/name notes/] ); - BeerDB::Beer->untaint_columns( - printable => [qw/abv name price notes/], - integer => [qw/style brewery score/], - date => [ qw/date/], - ); - - # set everything up - __PACKAGE__->setup("dbi:SQLite:t/beerdb.db"); - - 1; - =head1 AUTHOR Sebastian Riedel, C