From 3d3d38f2f6639c90c98c72dc0167a82d52ce9ec4 Mon Sep 17 00:00:00 2001 From: Sebastian Riedel Date: Sat, 16 Oct 2004 20:07:18 +0000 Subject: [PATCH] New Maypole::Application, we now use the Maypole::Plugin:: namespace and support special flags like -Setup git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@234 48953598-375a-da11-a14b-00016c27c3ee --- lib/Maypole/Application.pm | 55 ++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/lib/Maypole/Application.pm b/lib/Maypole/Application.pm index a39c4a1..e0c08ff 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; our @ISA; @@ -11,18 +12,31 @@ sub import { no strict 'refs'; push @{"${caller}::ISA"}, $self; foreach (@plugins) { - "Maypole::$_"->require or warn qq(Loading plugin "Maypole::$_" failed); - unshift @ISA, "Maypole::$_"; + if (/^\-Setup$/) { $caller->setup } + elsif (/^\-Debug$/) { + *{"$caller\::debug"} = sub { 1 }; + warn "Debugging enabled"; + } + else { + + # The plugin caller should be our application class + eval "package $caller; require Maypole::Plugin::$_"; + if ($@) { warn qq(Loading plugin "Maypole::Plugin::$_" failed: $@) } + else { + warn "Loaded plugin: Maypole::Plugin::$_" if $caller->debug; + unshift @ISA, "Maypole::Plugin::$_"; + } + } } } if ( $ENV{MOD_PERL} ) { - require Apache::MVC or die 'Loading Apache frontend failed'; - push @ISA, qw(Apache::MVC); + Apache::MVC->require or die "Loading Apache frontend failed: $@"; + push @ISA, 'Apache::MVC'; } else { - require CGI::Maypole or die 'Loading CGI frontend failed'; - push @ISA, qw(CGI::Maypole); + CGI::Maypole->require or die "Loading CGI frontend failed: $@"; + push @ISA, 'CGI::Maypole'; } 1; @@ -39,11 +53,36 @@ Maypole::Application - Maypole Universal Frontend This is a universal frontend for mod_perl1, mod_perl2 and CGI. -You can omit the Maypole:: prefix from plugins. -So Maypole::Config::YAML becomes Config::YAML. +You can omit the Maypole::Plugin:: prefix from plugins. +So Maypole::Plugin::Config::YAML becomes Config::YAML. use Maypole::Application qw(Config::YAML); +You can also set special flags like -Setup and -Debug. + + use Maypole::Application qw(-Debug Config::YAML -Setup); + +The position of plugins and flags in the chain is important, +because they are loaded/executed in the same order they appear. + +=head2 -Setup + + use Maypole::Application qw(-Setup); + +is equivalent to + + use Maypole::Application; + MyApp->setup; + +=head2 -Debug + + use Maypole::Application qw(-Debug); + +is equivalent to + + use Maypole::Application; + sub debug { 1 } + =head1 AUTHOR Sebastian Riedel, C -- 2.39.5