4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
10 __PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/;
12 our $VERSION = '5.00';
17 Catalyst - The Elegant MVC Web Application Framework
21 # use the helper to start a new application
25 # add models, views, controllers
26 script/create.pl model Something
27 script/create.pl view Stuff
28 script/create.pl controller Yada
33 # command line interface
39 use Catalyst qw/My::Module My::OtherModule/;
41 use Catalyst '-Debug';
43 use Catalyst qw/-Debug -Engine=CGI/;
45 sub default : Private { $_[1]->res->output('Hello') } );
47 sub index : Path('/index.html') {
48 my ( $self, $c ) = @_;
49 $c->res->output('Hello');
53 sub product : Regex('/^product[_]*(\d*).html$/') {
54 my ( $self, $c ) = @_;
55 $c->stash->{template} = 'product.tt';
56 $c->stash->{product} = $c->req->snippets->[0];
59 See also L<Catalyst::Manual::Intro>
63 Catalyst is based upon L<Maypole>, which you should consider for smaller
66 The key concept of Catalyst is DRY (Don't Repeat Yourself).
68 See L<Catalyst::Manual> for more documentation.
70 Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement.
71 Omit the C<Catalyst::Plugin::> prefix from the plugin name,
72 so C<Catalyst::Plugin::My::Module> becomes C<My::Module>.
74 use Catalyst 'My::Module';
76 Special flags like -Debug and -Engine can also be specifed as arguments when
79 use Catalyst qw/-Debug My::Module/;
81 The position of plugins and flags in the chain is important, because they are
82 loaded in exactly the order that they appear.
84 The following flags are supported:
90 enables debug output, i.e.:
92 use Catalyst '-Debug';
94 this is equivalent to:
101 Force Catalyst to use a specific engine.
102 Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.:
104 use Catalyst '-Engine=CGI';
114 Overload to enable debug messages.
122 Returns a hashref containing your applications settings.
127 my ( $self, @options ) = @_;
128 my $caller = caller(0);
130 # Prepare inheritance
131 unless ( $caller->isa($self) ) {
133 push @{"$caller\::ISA"}, $self;
136 if ( $caller->engine ) {
137 return; # Catalyst is already initialized
140 unless ( $caller->log ) {
141 $caller->log( Catalyst::Log->new );
145 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
147 *{"$caller\::debug"} = sub { 1 };
148 $caller->log->debug('Debug messages enabled');
151 my $engine = 'Catalyst::Engine::CGI';
152 my $dispatcher = 'Catalyst::Dispatcher';
155 if ( $ENV{MOD_PERL} ) {
159 if ( $mod_perl::VERSION >= 1.99 ) {
160 $engine = 'Catalyst::Engine::Apache::MP19';
163 $engine = 'Catalyst::Engine::Apache::MP13';
167 $caller->log->info("You are running an old helper script! ".
168 "Please update your scripts by regenerating the ".
169 "application and copying over the new scripts.")
170 if ( $ENV{CATALYST_SCRIPT_GEN} && (
171 $ENV{CATALYST_SCRIPT_GEN} <
172 $Catalyst::Helper::CATALYST_SCRIPT_GEN )) ;
178 next if $caller->debug;
180 *{"$caller\::debug"} = sub { 1 };
181 $caller->log->debug('Debug messages enabled');
184 elsif (/^-Dispatcher=(.*)$/) {
185 $dispatcher = "Catalyst::Dispatcher::$1";
188 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
189 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
192 my $plugin = "Catalyst::Plugin::$_";
196 if ($@) { die qq/Couldn't load plugin "$plugin", "$@"/ }
198 push @plugins, $plugin;
200 push @{"$caller\::ISA"}, $plugin;
207 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
208 $t->setCols('Class');
209 $t->setColWidth( 'Class', 75, 1 );
210 $t->addRow($_) for @plugins;
211 $caller->log->debug( 'Loaded plugins', $t->draw )
212 if ( @plugins && $caller->debug );
215 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
216 if $ENV{CATALYST_ENGINE};
219 die qq/Couldn't load engine "$engine", "$@"/ if $@;
222 push @{"$caller\::ISA"}, $engine;
224 $caller->engine($engine);
225 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
228 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
229 if $ENV{CATALYST_DISPATCHER};
231 $dispatcher->require;
232 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
235 push @{"$caller\::ISA"}, $dispatcher;
237 $caller->dispatcher($dispatcher);
238 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
244 Contains the engine class.
248 Contains the logging object. Unless it is already set Catalyst sets this up with a
249 C<Catalyst::Log> object. To use your own log class:
251 $c->log( MyLogger->new );
252 $c->log->info("now logging with my own logger!");
254 Your log class should implement the methods described in the C<Catalyst::Log>
262 FCGI and mod_perl2 support are considered experimental and may contain bugs.
264 You may encounter problems accessing the built in test server on public ip
265 addresses on the internet, thats because of a bug in HTTP::Daemon.
271 Join #catalyst on irc.perl.org.
275 http://lists.rawmode.org/mailman/listinfo/catalyst
276 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
282 =item L<Catalyst::Manual> - The Catalyst Manual
284 =item L<Catalyst::Engine> - Core Engine
286 =item L<Catalyst::Log> - The Log Class.
288 =item L<Catalyst::Request> - The Request Object
290 =item L<Catalyst::Response> - The Response Object
292 =item L<Catalyst::Test> - The test suite.
298 Sebastian Riedel, C<sri@oook.de>
302 Andy Grundman, Andrew Ford, Andrew Ruthven, Christian Hansen,
303 Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton,
304 Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg,
305 Tatsuhiko Miyagawa and all the others who've helped.
309 This library is free software . You can redistribute it and/or modify it under
310 the same terms as perl itself.