]> git.decadent.org.uk Git - maypole.git/blob - lib/Maypole/Application.pm
fun!!! =)
[maypole.git] / lib / Maypole / Application.pm
1 package Maypole::Application;
2
3 use strict;
4 use warnings;
5 use UNIVERSAL::require;
6 use Maypole;
7
8 # funny little gimmick ;)
9 my $banner = <<'';
10  __  __                         _
11 |  \/  | __ _ _   _ _ __   ___ | | ___
12 | |\/| |/ _` | | | | '_ \ / _ \| |/ _ \
13 | |  | | (_| | |_| | |_) | (_) | |  __/
14 |_|  |_|\__,_|\__, | .__/ \___/|_|\___|
15               |___/|_| -= VERSION =-
16
17 $banner =~ s/VERSION/$Maypole::VERSION/;
18 warn $banner;
19
20 our @ISA;
21
22 sub import {
23     my ( $self, @plugins ) = @_;
24     my $caller = caller(0);
25     no strict 'refs';
26     push @{"${caller}::ISA"}, $self;
27     foreach (@plugins) {
28         if    (/^\-Setup$/) { $caller->setup }
29         elsif (/^\-Debug$/) {
30             *{"$caller\::debug"} = sub { 1 };
31             warn "Debugging enabled";
32         }
33         else {
34
35             # The plugin caller should be our application class
36             eval "package $caller; require Maypole::Plugin::$_";
37             if ($@) { warn qq(Loading plugin "Maypole::Plugin::$_" failed: $@) }
38             else {
39                 warn "Loaded plugin: Maypole::Plugin::$_" if $caller->debug;
40                 unshift @ISA, "Maypole::Plugin::$_";
41             }
42         }
43     }
44 }
45
46 if ( $ENV{MOD_PERL} ) {
47     Apache::MVC->require or die "Loading Apache frontend failed: $@";
48     push @ISA, 'Apache::MVC';
49 }
50 else {
51     CGI::Maypole->require or die "Loading CGI frontend failed: $@";
52     push @ISA, 'CGI::Maypole';
53 }
54
55 1;
56
57 =head1 NAME
58
59 Maypole::Application - Maypole Universal Frontend
60
61 =head1 SYNOPSIS
62
63     use Maypole::Application;
64
65     use Maypole::Application qw(Config::YAML);
66
67     use Maypole::Application qw(-Debug Config::YAML -Setup);
68
69     use Maypole::Application qw(Config::YAML Loader -Setup -Debug);
70
71 =head1 DESCRIPTION
72
73 This is a universal frontend for mod_perl1, mod_perl2 and CGI.
74
75 You can omit the Maypole::Plugin:: prefix from plugins.
76 So Maypole::Plugin::Config::YAML becomes Config::YAML.
77
78     use Maypole::Application qw(Config::YAML);
79
80 You can also set special flags like -Setup and -Debug.
81
82     use Maypole::Application qw(-Debug Config::YAML -Setup);
83
84 The position of plugins and flags in the chain is important,
85 because they are loaded/executed in the same order they appear.
86
87 =head2 -Setup
88
89     use Maypole::Application qw(-Setup);
90
91 is equivalent to
92
93     use Maypole::Application;
94     MyApp->setup;
95
96 =head2 -Debug
97
98     use Maypole::Application qw(-Debug);
99
100 is equivalent to
101
102     use Maypole::Application;
103     sub debug { 1 }
104
105 =head1 AUTHOR
106
107 Sebastian Riedel, C<sri@oook.de>
108 Idea by Marcus Ramberg, C<marcus@thefeed.no>
109
110 =head1 LICENSE
111
112 You may distribute this code under the same terms as Perl itself.