4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
8 our $CATALYST_SCRIPT_GEN = 2;
10 __PACKAGE__->mk_classdata($_) for qw/dispatcher engine log/;
12 our $VERSION = '5.03';
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}
174 && ( $ENV{CATALYST_SCRIPT_GEN} < $CATALYST_SCRIPT_GEN ) );
181 next if $caller->debug;
183 *{"$caller\::debug"} = sub { 1 };
184 $caller->log->debug('Debug messages enabled');
187 elsif (/^-Dispatcher=(.*)$/) {
188 $dispatcher = "Catalyst::Dispatcher::$1";
191 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
192 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
195 my $plugin = "Catalyst::Plugin::$_";
199 if ($@) { die qq/Couldn't load plugin "$plugin", "$@"/ }
201 push @plugins, $plugin;
203 push @{"$caller\::ISA"}, $plugin;
210 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
211 $t->setCols('Class');
212 $t->setColWidth( 'Class', 75, 1 );
213 $t->addRow($_) for @plugins;
214 $caller->log->debug( 'Loaded plugins', $t->draw )
215 if ( @plugins && $caller->debug );
218 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
219 if $ENV{CATALYST_DISPATCHER};
221 $dispatcher->require;
222 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
225 push @{"$caller\::ISA"}, $dispatcher;
227 $caller->dispatcher($dispatcher);
228 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
231 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
232 if $ENV{CATALYST_ENGINE};
235 die qq/Couldn't load engine "$engine", "$@"/ if $@;
238 push @{"$caller\::ISA"}, $engine;
240 $caller->engine($engine);
241 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
246 Contains the engine class.
250 Contains the logging object. Unless it is already set Catalyst sets this up with a
251 C<Catalyst::Log> object. To use your own log class:
253 $c->log( MyLogger->new );
254 $c->log->info("now logging with my own logger!");
256 Your log class should implement the methods described in the C<Catalyst::Log>
259 =item $c->plugin( $name, $class, @args )
261 Instant plugins for Catalyst.
262 Classdata accessor/mutator will be created, class loaded and instantiated.
264 MyApp->plugin( 'prototype', 'HTML::Prototype' );
266 $c->prototype->define_javascript_functions;
271 my ( $class, $name, $plugin, @args ) = @_;
273 my $error = $UNIVERSAL::require::ERROR;
274 die qq/Couldn't load instant plugin "$plugin", "$error"/ if $error;
275 eval { $plugin->import };
276 $class->mk_classdata($name);
278 eval { $obj = $plugin->new(@args) };
279 die qq/Couldn't instantiate instant plugin "$plugin", "$@"/ if $@;
281 $class->log->debug(qq/Initialized instant plugin "$plugin" as "$name"/)
289 mod_perl2 support are considered experimental and may contain bugs.
295 Join #catalyst on irc.perl.org.
299 http://lists.rawmode.org/mailman/listinfo/catalyst
300 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
304 http://catalyst.perl.org
310 =item L<Catalyst::Manual> - The Catalyst Manual
312 =item L<Catalyst::Engine> - Core Engine
314 =item L<Catalyst::Log> - The Log Class.
316 =item L<Catalyst::Request> - The Request Object
318 =item L<Catalyst::Response> - The Response Object
320 =item L<Catalyst::Test> - The test suite.
326 Sebastian Riedel, C<sri@oook.de>
330 Andy Grundman, Andrew Ford, Andrew Ruthven, Autrijus Tang, Christian Hansen,
331 Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton,
332 Gary Ashton Jones, Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg,
333 Tatsuhiko Miyagawa and all the others who've helped.
337 This library is free software . You can redistribute it and/or modify it under
338 the same terms as perl itself.