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 unless ( $caller->isa($self) ) {
131 push @{"$caller\::ISA"}, $self;
134 if ( $caller->engine ) {
135 return; # Catalyst is allready initialized
138 unless ( $caller->log ) {
139 $caller->log( Catalyst::Log->new );
142 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
144 *{"$caller\::debug"} = sub { 1 };
145 $caller->log->debug('Debug messages enabled');
148 my $engine = 'Catalyst::Engine::CGI';
149 my $dispatcher = 'Catalyst::Dispatcher';
151 if ( $ENV{MOD_PERL} ) {
155 if ( $mod_perl::VERSION >= 1.99 ) {
156 $engine = 'Catalyst::Engine::Apache::MP2';
159 $engine = 'Catalyst::Engine::Apache::MP1';
166 next if $caller->debug;
168 *{"$caller\::debug"} = sub { 1 };
169 $caller->log->debug('Debug messages enabled');
171 elsif (/^-Dispatcher=(.*)$/) {
172 $dispatcher = "Catalyst::Dispatcher::$1";
174 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
175 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
177 my $plugin = "Catalyst::Plugin::$_";
182 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
185 push @plugins, $plugin;
187 push @{"$caller\::ISA"}, $plugin;
191 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
192 $t->setCols('Class');
193 $t->setColWidth( 'Class', 75, 1 );
194 $t->addRow($_) for @plugins;
195 $caller->log->debug( 'Loaded plugins', $t->draw )
196 if ( @plugins && $caller->debug );
199 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
200 if $ENV{CATALYST_ENGINE};
203 die qq/Couldn't load engine "$engine", "$@"/ if $@;
206 push @{"$caller\::ISA"}, $engine;
208 $caller->engine($engine);
209 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
212 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
213 if $ENV{CATALYST_DISPATCHER};
215 $dispatcher->require;
216 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
219 push @{"$caller\::ISA"}, $dispatcher;
221 $caller->dispatcher($dispatcher);
222 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
228 Contains the engine class.
232 Contains the logging object. Unless it is already set Catalyst sets this up with a
233 C<Catalyst::Log> object. To use your own log class:
235 $c->log( MyLogger->new );
236 $c->log->info("now logging with my own logger!");
238 Your log class should implement the methods described in the C<Catalyst::Log>
248 Join #catalyst on irc.perl.org.
252 http://lists.rawmode.org/mailman/listinfo/catalyst
253 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
259 =item L<Catalyst::Manual> - The Catalyst Manual
261 =item L<Catalyst::Engine> - Core Engine
263 =item L<Catalyst::Log> - The Log Class.
265 =item L<Catalyst::Request> - The Request Object
267 =item L<Catalyst::Response> - The Response Object
269 =item L<Catalyst::Test> - The test suite.
275 Sebastian Riedel, C<sri@oook.de>
279 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
280 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
281 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
282 and all the others who've helped.
286 This library is free software . You can redistribute it and/or modify it under
287 the same terms as perl itself.