4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
10 __PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/;
12 our $VERSION = '5.01';
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 ( $ENV{MOD_PERL_API_VERSION} == 2 ) {
160 $engine = 'Catalyst::Engine::Apache::MP20';
162 elsif ( $mod_perl::VERSION >= 1.99 ) {
163 $engine = 'Catalyst::Engine::Apache::MP19';
166 $engine = 'Catalyst::Engine::Apache::MP13';
170 $caller->log->info( "You are running an old helper script! "
171 . "Please update your scripts by regenerating the "
172 . "application and copying over the new scripts." )
173 if ( $ENV{CATALYST_SCRIPT_GEN}
175 $ENV{CATALYST_SCRIPT_GEN} < $Catalyst::Helper::CATALYST_SCRIPT_GEN )
183 next if $caller->debug;
185 *{"$caller\::debug"} = sub { 1 };
186 $caller->log->debug('Debug messages enabled');
189 elsif (/^-Dispatcher=(.*)$/) {
190 $dispatcher = "Catalyst::Dispatcher::$1";
193 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
194 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
197 my $plugin = "Catalyst::Plugin::$_";
201 if ($@) { die qq/Couldn't load plugin "$plugin", "$@"/ }
203 push @plugins, $plugin;
205 push @{"$caller\::ISA"}, $plugin;
212 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
213 $t->setCols('Class');
214 $t->setColWidth( 'Class', 75, 1 );
215 $t->addRow($_) for @plugins;
216 $caller->log->debug( 'Loaded plugins', $t->draw )
217 if ( @plugins && $caller->debug );
220 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
221 if $ENV{CATALYST_ENGINE};
224 die qq/Couldn't load engine "$engine", "$@"/ if $@;
227 push @{"$caller\::ISA"}, $engine;
229 $caller->engine($engine);
230 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
233 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
234 if $ENV{CATALYST_DISPATCHER};
236 $dispatcher->require;
237 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
240 push @{"$caller\::ISA"}, $dispatcher;
242 $caller->dispatcher($dispatcher);
243 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
249 Contains the engine class.
253 Contains the logging object. Unless it is already set Catalyst sets this up with a
254 C<Catalyst::Log> object. To use your own log class:
256 $c->log( MyLogger->new );
257 $c->log->info("now logging with my own logger!");
259 Your log class should implement the methods described in the C<Catalyst::Log>
267 FCGI and mod_perl2 support are considered experimental and may contain bugs.
269 You may encounter problems accessing the built in test server on public ip
270 addresses on the internet, thats because of a bug in HTTP::Daemon.
276 Join #catalyst on irc.perl.org.
280 http://lists.rawmode.org/mailman/listinfo/catalyst
281 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
285 http://catalyst.perl.org
291 =item L<Catalyst::Manual> - The Catalyst Manual
293 =item L<Catalyst::Engine> - Core Engine
295 =item L<Catalyst::Log> - The Log Class.
297 =item L<Catalyst::Request> - The Request Object
299 =item L<Catalyst::Response> - The Response Object
301 =item L<Catalyst::Test> - The test suite.
307 Sebastian Riedel, C<sri@oook.de>
311 Andy Grundman, Andrew Ford, Andrew Ruthven, Christian Hansen,
312 Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton,
313 Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg,
314 Tatsuhiko Miyagawa and all the others who've helped.
318 This library is free software . You can redistribute it and/or modify it under
319 the same terms as perl itself.