Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst; |
2 | |
3 | use strict; |
4 | use base 'Class::Data::Inheritable'; |
5 | use UNIVERSAL::require; |
6 | use Catalyst::Log; |
7 | |
70cb38f0 |
8 | __PACKAGE__->mk_classdata($_) for qw/_config engine log/; |
fc7ec1d9 |
9 | |
26e6b226 |
10 | our $VERSION = '4.33'; |
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 | |
43 | __PACKAGE__->action( '!default' => sub { $_[1]->res->output('Hello') } ); |
44 | |
45 | __PACKAGE__->action( |
46 | 'index.html' => sub { |
47 | my ( $self, $c ) = @_; |
48 | $c->res->output('Hello'); |
49 | $c->forward('_foo'); |
50 | } |
51 | ); |
52 | |
53 | __PACKAGE__->action( |
54 | '/^product[_]*(\d*).html$/' => sub { |
55 | my ( $self, $c ) = @_; |
56 | $c->stash->{template} = 'product.tt'; |
57 | $c->stash->{product} = $c->req->snippets->[0]; |
58 | } |
59 | ); |
60 | |
3803e98f |
61 | See also L<Catalyst::Manual::Intro> |
62 | |
fc7ec1d9 |
63 | =head1 DESCRIPTION |
64 | |
65 | Catalyst is based upon L<Maypole>, which you should consider for smaller |
66 | projects. |
67 | |
68 | The key concept of Catalyst is DRY (Don't Repeat Yourself). |
69 | |
70 | See L<Catalyst::Manual> for more documentation. |
71 | |
23f9d934 |
72 | Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement. |
73 | Omit the C<Catalyst::Plugin::> prefix from the plugin name, |
74 | so C<Catalyst::Plugin::My::Module> becomes C<My::Module>. |
fc7ec1d9 |
75 | |
76 | use Catalyst 'My::Module'; |
77 | |
23f9d934 |
78 | Special flags like -Debug and -Engine can also be specifed as arguments when |
79 | Catalyst is loaded: |
fc7ec1d9 |
80 | |
81 | use Catalyst qw/-Debug My::Module/; |
82 | |
23f9d934 |
83 | The position of plugins and flags in the chain is important, because they are |
84 | loaded in exactly the order that they appear. |
fc7ec1d9 |
85 | |
23f9d934 |
86 | The following flags are supported: |
87 | |
88 | =over 4 |
89 | |
90 | =item -Debug |
91 | |
92 | enables debug output, i.e.: |
fc7ec1d9 |
93 | |
94 | use Catalyst '-Debug'; |
95 | |
23f9d934 |
96 | this is equivalent to: |
fc7ec1d9 |
97 | |
98 | use Catalyst; |
99 | sub debug { 1 } |
100 | |
23f9d934 |
101 | =item -Engine |
fc7ec1d9 |
102 | |
103 | Force Catalyst to use a specific engine. |
23f9d934 |
104 | Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.: |
fc7ec1d9 |
105 | |
106 | use Catalyst '-Engine=CGI'; |
107 | |
23f9d934 |
108 | =back |
fc7ec1d9 |
109 | |
23f9d934 |
110 | =head1 METHODS |
111 | |
112 | =over 4 |
113 | |
114 | =item debug |
fc7ec1d9 |
115 | |
116 | Overload to enable debug messages. |
117 | |
118 | =cut |
119 | |
120 | sub debug { 0 } |
121 | |
23f9d934 |
122 | =item config |
fc7ec1d9 |
123 | |
124 | Returns a hashref containing your applications settings. |
125 | |
126 | =cut |
127 | |
128 | sub config { |
129 | my $self = shift; |
130 | $self->_config( {} ) unless $self->_config; |
131 | if ( $_[0] ) { |
132 | my $config = $_[1] ? {@_} : $_[0]; |
133 | while ( my ( $key, $val ) = each %$config ) { |
134 | $self->_config->{$key} = $val; |
135 | } |
136 | } |
137 | return $self->_config; |
138 | } |
139 | |
140 | sub import { |
141 | my ( $self, @options ) = @_; |
142 | my $caller = caller(0); |
143 | |
144 | # Class |
145 | { |
146 | no strict 'refs'; |
147 | *{"$caller\::handler"} = |
148 | sub { Catalyst::Engine::handler( $caller, @_ ) }; |
1c99e125 |
149 | |
150 | unless ( $caller->isa($self) ) { |
151 | push @{"$caller\::ISA"}, $self; |
152 | } |
153 | } |
154 | |
32620e3e |
155 | unless ( $caller->log ) { |
156 | $caller->log( Catalyst::Log->new ); |
fc7ec1d9 |
157 | } |
fc7ec1d9 |
158 | |
159 | # Options |
160 | my $engine = |
161 | $ENV{MOD_PERL} ? 'Catalyst::Engine::Apache' : 'Catalyst::Engine::CGI'; |
162 | foreach (@options) { |
163 | if (/^\-Debug$/) { |
164 | no warnings; |
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 | |
174 | # Plugin caller should be our application class |
175 | eval "package $caller; require $plugin"; |
176 | if ($@) { |
177 | $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/); |
178 | } |
179 | else { |
180 | $caller->log->debug(qq/Loaded plugin "$plugin"/) |
181 | if $caller->debug; |
502619e5 |
182 | no strict 'refs'; |
183 | push @{"$caller\::ISA"}, $plugin; |
fc7ec1d9 |
184 | } |
185 | } |
186 | } |
187 | |
188 | # Engine |
189 | $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}" |
190 | if $ENV{CATALYST_ENGINE}; |
191 | $engine->require; |
192 | die qq/Couldn't load engine "$engine", "$@"/ if $@; |
502619e5 |
193 | { |
194 | no strict 'refs'; |
195 | push @{"$caller\::ISA"}, $engine; |
196 | } |
70cb38f0 |
197 | $caller->engine($engine); |
fc7ec1d9 |
198 | $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug; |
199 | } |
200 | |
70cb38f0 |
201 | =item $c->engine |
202 | |
203 | Contains the engine class. |
204 | |
145074c2 |
205 | =item $c->log |
206 | |
207 | Contains the logging object. Unless it is already set Catalyst sets this up with a |
208 | C<Catalyst::Log> object. To use your own log class: |
209 | |
210 | $c->log( MyLogger->new ); |
211 | $c->log->info("now logging with my own logger!"); |
212 | |
213 | Your log class should implement the methods described in the C<Catalyst::Log> |
214 | man page. |
215 | |
216 | |
23f9d934 |
217 | =back |
218 | |
3cb1db8c |
219 | =head1 SUPPORT |
220 | |
221 | IRC: |
222 | |
223 | Join #catalyst on irc.perl.org. |
224 | |
225 | Mailing-Lists: |
226 | |
227 | http://lists.rawmode.org/mailman/listinfo/catalyst |
228 | http://lists.rawmode.org/mailman/listinfo/catalyst-dev |
229 | |
fc7ec1d9 |
230 | =head1 SEE ALSO |
231 | |
232 | L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>, |
233 | L<Catalyst::Response>, L<Catalyst::Engine> |
234 | |
235 | =head1 AUTHOR |
236 | |
237 | Sebastian Riedel, C<sri@oook.de> |
238 | |
239 | =head1 THANK YOU |
240 | |
bc024080 |
241 | Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks, |
b0b7c5e0 |
242 | Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones, |
243 | Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa |
244 | and all the others who've helped. |
fc7ec1d9 |
245 | |
246 | =head1 LICENSE |
247 | |
248 | This library is free software . You can redistribute it and/or modify it under |
249 | the same terms as perl itself. |
250 | |
251 | =cut |
252 | |
253 | 1; |