4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
8 use Text::ASCIITable::Wrap 'wrap';
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 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 );
143 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
145 *{"$caller\::debug"} = sub { 1 };
146 $caller->log->debug('Debug messages enabled');
149 my $engine = 'Catalyst::Engine::CGI';
150 my $dispatcher = 'Catalyst::Dispatcher';
152 if ( $ENV{MOD_PERL} ) {
156 if ( $mod_perl::VERSION >= 1.99 ) {
157 $engine = 'Catalyst::Engine::Apache::MP2';
160 $engine = 'Catalyst::Engine::Apache::MP1';
167 next if $caller->debug;
169 *{"$caller\::debug"} = sub { 1 };
170 $caller->log->debug('Debug messages enabled');
172 elsif (/^-Dispatcher=(.*)$/) {
173 $dispatcher = "Catalyst::Dispatcher::$1";
175 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
176 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
178 my $plugin = "Catalyst::Plugin::$_";
183 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
186 push @plugins, $plugin;
188 push @{"$caller\::ISA"}, $plugin;
192 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
193 $t->setCols('Class');
194 $t->setColWidth( 'Class', 75, 1 );
195 $t->addRow( wrap( $_, 75 ) ) for @plugins;
196 $caller->log->debug( 'Loaded plugins', $t->draw )
197 if ( @plugins && $caller->debug );
200 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
201 if $ENV{CATALYST_ENGINE};
204 die qq/Couldn't load engine "$engine", "$@"/ if $@;
207 push @{"$caller\::ISA"}, $engine;
209 $caller->engine($engine);
210 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
213 $dispatcher = "Catalyst::Dispatcher::$ENV{CATALYST_DISPATCHER}"
214 if $ENV{CATALYST_DISPATCHER};
216 $dispatcher->require;
217 die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
220 push @{"$caller\::ISA"}, $dispatcher;
222 $caller->dispatcher($dispatcher);
223 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/) if $caller->debug;
229 Contains the engine class.
233 Contains the logging object. Unless it is already set Catalyst sets this up with a
234 C<Catalyst::Log> object. To use your own log class:
236 $c->log( MyLogger->new );
237 $c->log->info("now logging with my own logger!");
239 Your log class should implement the methods described in the C<Catalyst::Log>
249 Join #catalyst on irc.perl.org.
253 http://lists.rawmode.org/mailman/listinfo/catalyst
254 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
260 =item L<Catalyst::Manual> - The Catalyst Manual
262 =item L<Catalyst::Engine> - Core Engine
264 =item L<Catalyst::Log> - The Log Class.
266 =item L<Catalyst::Request> - The Request Object
268 =item L<Catalyst::Response> - The Response Object
270 =item L<Catalyst::Test> - The test suite.
276 Sebastian Riedel, C<sri@oook.de>
280 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
281 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
282 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
283 and all the others who've helped.
287 This library is free software . You can redistribute it and/or modify it under
288 the same terms as perl itself.