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