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