4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
9 __PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/;
11 our $VERSION = '5.00';
16 Catalyst - The Elegant MVC Web Application Framework
20 # use the helper to start a new application
24 # add models, views, controllers
25 script/create.pl model Something
26 script/create.pl view Stuff
27 script/create.pl controller Yada
32 # command line interface
38 use Catalyst qw/My::Module My::OtherModule/;
40 use Catalyst '-Debug';
42 use Catalyst qw/-Debug -Engine=CGI/;
44 sub default : Private { $_[1]->res->output('Hello') } );
46 sub index : Path('/index.html') {
47 my ( $self, $c ) = @_;
48 $c->res->output('Hello');
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];
58 See also L<Catalyst::Manual::Intro>
62 Catalyst is based upon L<Maypole>, which you should consider for smaller
65 The key concept of Catalyst is DRY (Don't Repeat Yourself).
67 See L<Catalyst::Manual> for more documentation.
69 Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement.
70 Omit the C<Catalyst::Plugin::> prefix from the plugin name,
71 so C<Catalyst::Plugin::My::Module> becomes C<My::Module>.
73 use Catalyst 'My::Module';
75 Special flags like -Debug and -Engine can also be specifed as arguments when
78 use Catalyst qw/-Debug My::Module/;
80 The position of plugins and flags in the chain is important, because they are
81 loaded in exactly the order that they appear.
83 The following flags are supported:
89 enables debug output, i.e.:
91 use Catalyst '-Debug';
93 this is equivalent to:
100 Force Catalyst to use a specific engine.
101 Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.:
103 use Catalyst '-Engine=CGI';
113 Overload to enable debug messages.
121 Returns a hashref containing your applications settings.
126 my ( $self, @options ) = @_;
127 my $caller = caller(0);
129 # Prepare inheritance
130 unless ( $caller->isa($self) ) {
132 push @{"$caller\::ISA"}, $self;
135 if ( $caller->engine ) {
136 return; # Catalyst is allready initialized
139 unless ( $caller->log ) {
140 $caller->log( Catalyst::Log->new );
144 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
146 *{"$caller\::debug"} = sub { 1 };
147 $caller->log->debug('Debug messages enabled');
150 my $engine = 'Catalyst::Engine::CGI';
151 my $dispatcher = 'Catalyst::Dispatcher';
154 if ( $ENV{MOD_PERL} ) {
158 if ( $mod_perl::VERSION >= 1.99 ) {
159 $engine = 'Catalyst::Engine::Apache::MP2';
162 $engine = 'Catalyst::Engine::Apache::MP1';
171 next if $caller->debug;
173 *{"$caller\::debug"} = sub { 1 };
174 $caller->log->debug('Debug messages enabled');
177 elsif (/^-Dispatcher=(.*)$/) {
178 $dispatcher = "Catalyst::Dispatcher::$1";
181 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
182 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
185 my $plugin = "Catalyst::Plugin::$_";
190 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
193 push @plugins, $plugin;
195 push @{"$caller\::ISA"}, $plugin;
202 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
203 $t->setCols('Class');
204 $t->setColWidth( 'Class', 75, 1 );
205 $t->addRow($_) for @plugins;
206 $caller->log->debug( 'Loaded plugins', $t->draw )
207 if ( @plugins && $caller->debug );
210 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
211 if $ENV{CATALYST_ENGINE};
214 die qq/Couldn't load engine "$engine", "$@"/ if $@;
217 push @{"$caller\::ISA"}, $engine;
219 $caller->engine($engine);
220 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
223 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
224 if $ENV{CATALYST_DISPATCHER};
226 $dispatcher->require;
227 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
230 push @{"$caller\::ISA"}, $dispatcher;
232 $caller->dispatcher($dispatcher);
233 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
239 Contains the engine class.
243 Contains the logging object. Unless it is already set Catalyst sets this up with a
244 C<Catalyst::Log> object. To use your own log class:
246 $c->log( MyLogger->new );
247 $c->log->info("now logging with my own logger!");
249 Your log class should implement the methods described in the C<Catalyst::Log>
259 Join #catalyst on irc.perl.org.
263 http://lists.rawmode.org/mailman/listinfo/catalyst
264 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
270 =item L<Catalyst::Manual> - The Catalyst Manual
272 =item L<Catalyst::Engine> - Core Engine
274 =item L<Catalyst::Log> - The Log Class.
276 =item L<Catalyst::Request> - The Request Object
278 =item L<Catalyst::Response> - The Response Object
280 =item L<Catalyst::Test> - The test suite.
286 Sebastian Riedel, C<sri@oook.de>
290 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
291 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
292 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
293 and all the others who've helped.
297 This library is free software . You can redistribute it and/or modify it under
298 the same terms as perl itself.