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::MP19';
162 $engine = 'Catalyst::Engine::Apache::MP13';
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::$_";
189 if ($@) { die qq/Couldn't load plugin "$plugin", "$@"/ }
191 push @plugins, $plugin;
193 push @{"$caller\::ISA"}, $plugin;
200 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
201 $t->setCols('Class');
202 $t->setColWidth( 'Class', 75, 1 );
203 $t->addRow($_) for @plugins;
204 $caller->log->debug( 'Loaded plugins', $t->draw )
205 if ( @plugins && $caller->debug );
208 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
209 if $ENV{CATALYST_ENGINE};
212 die qq/Couldn't load engine "$engine", "$@"/ if $@;
215 push @{"$caller\::ISA"}, $engine;
217 $caller->engine($engine);
218 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
221 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
222 if $ENV{CATALYST_DISPATCHER};
224 $dispatcher->require;
225 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
228 push @{"$caller\::ISA"}, $dispatcher;
230 $caller->dispatcher($dispatcher);
231 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
237 Contains the engine class.
241 Contains the logging object. Unless it is already set Catalyst sets this up with a
242 C<Catalyst::Log> object. To use your own log class:
244 $c->log( MyLogger->new );
245 $c->log->info("now logging with my own logger!");
247 Your log class should implement the methods described in the C<Catalyst::Log>
255 FCGI and mod_perl2 support are considered experimental and may contain bugs.
257 You may encounter problems accessing the built in test server on public ip
258 addresses on the internet, thats because of a bug in HTTP::Daemon.
264 Join #catalyst on irc.perl.org.
268 http://lists.rawmode.org/mailman/listinfo/catalyst
269 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
275 =item L<Catalyst::Manual> - The Catalyst Manual
277 =item L<Catalyst::Engine> - Core Engine
279 =item L<Catalyst::Log> - The Log Class.
281 =item L<Catalyst::Request> - The Request Object
283 =item L<Catalyst::Response> - The Response Object
285 =item L<Catalyst::Test> - The test suite.
291 Sebastian Riedel, C<sri@oook.de>
295 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
296 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
297 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
298 and all the others who've helped.
302 This library is free software . You can redistribute it and/or modify it under
303 the same terms as perl itself.