Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst; |
2 | |
3 | use strict; |
ac733264 |
4 | use base 'Catalyst::Base'; |
fc7ec1d9 |
5 | use UNIVERSAL::require; |
6 | use Catalyst::Log; |
0f7ecc53 |
7 | use Text::ASCIITable; |
fc7ec1d9 |
8 | |
ac733264 |
9 | __PACKAGE__->mk_classdata($_) for qw/engine log/; |
fc7ec1d9 |
10 | |
87e67021 |
11 | our $VERSION = '5.00'; |
fc7ec1d9 |
12 | our @ISA; |
13 | |
14 | =head1 NAME |
15 | |
16 | Catalyst - The Elegant MVC Web Application Framework |
17 | |
18 | =head1 SYNOPSIS |
19 | |
20 | # use the helper to start a new application |
91864987 |
21 | catalyst.pl MyApp |
fc7ec1d9 |
22 | cd MyApp |
23 | |
24 | # add models, views, controllers |
d01df17d |
25 | script/create.pl model Something |
26 | script/create.pl view Stuff |
27 | script/create.pl controller Yada |
fc7ec1d9 |
28 | |
29 | # built in testserver |
d01df17d |
30 | script/server.pl |
fc7ec1d9 |
31 | |
32 | # command line interface |
d01df17d |
33 | script/test.pl /yada |
fc7ec1d9 |
34 | |
35 | |
fc7ec1d9 |
36 | use Catalyst; |
37 | |
38 | use Catalyst qw/My::Module My::OtherModule/; |
39 | |
40 | use Catalyst '-Debug'; |
41 | |
42 | use Catalyst qw/-Debug -Engine=CGI/; |
43 | |
5a8ed4fe |
44 | sub default : Private { $_[1]->res->output('Hello') } ); |
45 | |
e3dc9d78 |
46 | sub index : Path('/index.html') { |
5a8ed4fe |
47 | my ( $self, $c ) = @_; |
48 | $c->res->output('Hello'); |
49 | $c->forward('_foo'); |
50 | } |
51 | |
52 | sub product : Regex('/^product[_]*(\d*).html$/') { |
53 | my ( $self, $c ) = @_; |
54 | $c->stash->{template} = 'product.tt'; |
55 | $c->stash->{product} = $c->req->snippets->[0]; |
56 | } |
fc7ec1d9 |
57 | |
3803e98f |
58 | See also L<Catalyst::Manual::Intro> |
59 | |
fc7ec1d9 |
60 | =head1 DESCRIPTION |
61 | |
62 | Catalyst is based upon L<Maypole>, which you should consider for smaller |
63 | projects. |
64 | |
65 | The key concept of Catalyst is DRY (Don't Repeat Yourself). |
66 | |
67 | See L<Catalyst::Manual> for more documentation. |
68 | |
23f9d934 |
69 | Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement. |
1985c30b |
70 | Omit the C<Catalyst::Plugin::> prefix from the plugin name, |
23f9d934 |
71 | so C<Catalyst::Plugin::My::Module> becomes C<My::Module>. |
fc7ec1d9 |
72 | |
73 | use Catalyst 'My::Module'; |
74 | |
23f9d934 |
75 | Special flags like -Debug and -Engine can also be specifed as arguments when |
76 | Catalyst is loaded: |
fc7ec1d9 |
77 | |
78 | use Catalyst qw/-Debug My::Module/; |
79 | |
23f9d934 |
80 | The position of plugins and flags in the chain is important, because they are |
81 | loaded in exactly the order that they appear. |
fc7ec1d9 |
82 | |
23f9d934 |
83 | The following flags are supported: |
84 | |
85 | =over 4 |
86 | |
87 | =item -Debug |
88 | |
89 | enables debug output, i.e.: |
fc7ec1d9 |
90 | |
91 | use Catalyst '-Debug'; |
92 | |
23f9d934 |
93 | this is equivalent to: |
fc7ec1d9 |
94 | |
95 | use Catalyst; |
96 | sub debug { 1 } |
97 | |
23f9d934 |
98 | =item -Engine |
fc7ec1d9 |
99 | |
100 | Force Catalyst to use a specific engine. |
23f9d934 |
101 | Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.: |
fc7ec1d9 |
102 | |
103 | use Catalyst '-Engine=CGI'; |
104 | |
23f9d934 |
105 | =back |
fc7ec1d9 |
106 | |
23f9d934 |
107 | =head1 METHODS |
108 | |
109 | =over 4 |
110 | |
111 | =item debug |
fc7ec1d9 |
112 | |
113 | Overload to enable debug messages. |
114 | |
115 | =cut |
116 | |
117 | sub debug { 0 } |
118 | |
23f9d934 |
119 | =item config |
fc7ec1d9 |
120 | |
121 | Returns a hashref containing your applications settings. |
122 | |
123 | =cut |
124 | |
fc7ec1d9 |
125 | sub import { |
126 | my ( $self, @options ) = @_; |
127 | my $caller = caller(0); |
128 | |
22402712 |
129 | unless ( $caller->isa($self) ) { |
fc7ec1d9 |
130 | no strict 'refs'; |
22402712 |
131 | push @{"$caller\::ISA"}, $self; |
1c99e125 |
132 | } |
133 | |
d96e14c2 |
134 | if ( $caller->engine ) { |
ac733264 |
135 | return; # Catalyst is allready initialized |
d96e14c2 |
136 | } |
137 | |
32620e3e |
138 | unless ( $caller->log ) { |
139 | $caller->log( Catalyst::Log->new ); |
fc7ec1d9 |
140 | } |
fc7ec1d9 |
141 | |
1985c30b |
142 | if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) { |
143 | no strict 'refs'; |
144 | *{"$caller\::debug"} = sub { 1 }; |
145 | $caller->log->debug('Debug messages enabled'); |
146 | } |
147 | |
91dc9907 |
148 | my $engine = 'Catalyst::Engine::CGI'; |
6dc87a0f |
149 | |
150 | if ( $ENV{MOD_PERL} ) { |
151 | |
152 | require mod_perl; |
153 | |
154 | if ( $mod_perl::VERSION >= 1.99 ) { |
91dc9907 |
155 | $engine = 'Catalyst::Engine::Apache::MP2'; |
6dc87a0f |
156 | } |
157 | else { |
91dc9907 |
158 | $engine = 'Catalyst::Engine::Apache::MP1'; |
6dc87a0f |
159 | } |
160 | } |
1985c30b |
161 | |
937fcdd8 |
162 | my @plugins; |
fc7ec1d9 |
163 | foreach (@options) { |
164 | if (/^\-Debug$/) { |
1985c30b |
165 | next if $caller->debug; |
fc7ec1d9 |
166 | no strict 'refs'; |
1c99e125 |
167 | *{"$caller\::debug"} = sub { 1 }; |
fc7ec1d9 |
168 | $caller->log->debug('Debug messages enabled'); |
169 | } |
170 | elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" } |
171 | elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) } |
172 | else { |
173 | my $plugin = "Catalyst::Plugin::$_"; |
174 | |
c4695f3a |
175 | $plugin->require; |
91dc9907 |
176 | |
fc7ec1d9 |
177 | if ($@) { |
178 | $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/); |
179 | } |
180 | else { |
f5f84847 |
181 | push @plugins, $plugin; |
502619e5 |
182 | no strict 'refs'; |
183 | push @{"$caller\::ISA"}, $plugin; |
fc7ec1d9 |
184 | } |
185 | } |
186 | } |
0f7ecc53 |
187 | my $t = Text::ASCIITable->new; |
188 | $t->setCols('Class'); |
0822f9a4 |
189 | $t->setColWidth( 'Class', 75, 1 ); |
0f7ecc53 |
190 | $t->addRow($_) for @plugins; |
191 | $caller->log->debug( 'Loaded plugins', $t->draw ) |
937fcdd8 |
192 | if ( @plugins && $caller->debug ); |
fc7ec1d9 |
193 | |
194 | # Engine |
195 | $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}" |
196 | if $ENV{CATALYST_ENGINE}; |
d96e14c2 |
197 | |
fc7ec1d9 |
198 | $engine->require; |
199 | die qq/Couldn't load engine "$engine", "$@"/ if $@; |
502619e5 |
200 | { |
201 | no strict 'refs'; |
970cc51d |
202 | push @{"$caller\::ISA"}, $engine; |
502619e5 |
203 | } |
70cb38f0 |
204 | $caller->engine($engine); |
fc7ec1d9 |
205 | $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug; |
206 | } |
207 | |
70cb38f0 |
208 | =item $c->engine |
209 | |
210 | Contains the engine class. |
211 | |
145074c2 |
212 | =item $c->log |
213 | |
214 | Contains the logging object. Unless it is already set Catalyst sets this up with a |
215 | C<Catalyst::Log> object. To use your own log class: |
216 | |
217 | $c->log( MyLogger->new ); |
218 | $c->log->info("now logging with my own logger!"); |
219 | |
220 | Your log class should implement the methods described in the C<Catalyst::Log> |
221 | man page. |
222 | |
223 | |
23f9d934 |
224 | =back |
225 | |
3cb1db8c |
226 | =head1 SUPPORT |
227 | |
228 | IRC: |
229 | |
230 | Join #catalyst on irc.perl.org. |
231 | |
232 | Mailing-Lists: |
233 | |
234 | http://lists.rawmode.org/mailman/listinfo/catalyst |
235 | http://lists.rawmode.org/mailman/listinfo/catalyst-dev |
1985c30b |
236 | |
fc7ec1d9 |
237 | =head1 SEE ALSO |
238 | |
239 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
240 | L<Catalyst::Response>, L<Catalyst::Engine> |
241 | |
242 | =head1 AUTHOR |
243 | |
244 | Sebastian Riedel, C<sri@oook.de> |
245 | |
246 | =head1 THANK YOU |
247 | |
bc024080 |
248 | Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks, |
b0b7c5e0 |
249 | Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones, |
250 | Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa |
251 | and all the others who've helped. |
fc7ec1d9 |
252 | |
253 | =head1 LICENSE |
254 | |
255 | This library is free software . You can redistribute it and/or modify it under |
256 | the same terms as perl itself. |
257 | |
258 | =cut |
259 | |
260 | 1; |