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