4 use base 'Class::Data::Inheritable';
5 use UNIVERSAL::require;
8 __PACKAGE__->mk_classdata($_) for qw/_config engine log/;
10 our $VERSION = '5.00';
15 Catalyst - The Elegant MVC Web Application Framework
19 # use the helper to start a new application
23 # add models, views, controllers
24 script/create.pl model Something
25 script/create.pl view Stuff
26 script/create.pl controller Yada
31 # command line interface
37 use Catalyst qw/My::Module My::OtherModule/;
39 use Catalyst '-Debug';
41 use Catalyst qw/-Debug -Engine=CGI/;
43 __PACKAGE__->action( '!default' => sub { $_[1]->res->output('Hello') } );
47 my ( $self, $c ) = @_;
48 $c->res->output('Hello');
54 '/^product[_]*(\d*).html$/' => sub {
55 my ( $self, $c ) = @_;
56 $c->stash->{template} = 'product.tt';
57 $c->stash->{product} = $c->req->snippets->[0];
61 See also L<Catalyst::Manual::Intro>
65 Catalyst is based upon L<Maypole>, which you should consider for smaller
68 The key concept of Catalyst is DRY (Don't Repeat Yourself).
70 See L<Catalyst::Manual> for more documentation.
72 Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement.
73 Omit the C<Catalyst::Plugin::> prefix from the plugin name,
74 so C<Catalyst::Plugin::My::Module> becomes C<My::Module>.
76 use Catalyst 'My::Module';
78 Special flags like -Debug and -Engine can also be specifed as arguments when
81 use Catalyst qw/-Debug My::Module/;
83 The position of plugins and flags in the chain is important, because they are
84 loaded in exactly the order that they appear.
86 The following flags are supported:
92 enables debug output, i.e.:
94 use Catalyst '-Debug';
96 this is equivalent to:
103 Force Catalyst to use a specific engine.
104 Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.:
106 use Catalyst '-Engine=CGI';
116 Overload to enable debug messages.
124 Returns a hashref containing your applications settings.
130 $self->_config( {} ) unless $self->_config;
132 my $config = $_[1] ? {@_} : $_[0];
133 while ( my ( $key, $val ) = each %$config ) {
134 $self->_config->{$key} = $val;
137 return $self->_config;
141 my ( $self, @options ) = @_;
142 my $caller = caller(0);
144 unless ( $caller->isa($self) ) {
146 push @{"$caller\::ISA"}, $self;
149 if ( $caller->engine ) {
150 return; # Catalyst is allready initialized
153 unless ( $caller->log ) {
154 $caller->log( Catalyst::Log->new );
157 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
159 *{"$caller\::debug"} = sub { 1 };
160 $caller->log->debug('Debug messages enabled');
164 my $engine = $ENV{MOD_PERL}
165 ? 'Catalyst::Engine::Apache'
166 : 'Catalyst::Engine::CGI';
170 next if $caller->debug;
172 *{"$caller\::debug"} = sub { 1 };
173 $caller->log->debug('Debug messages enabled');
175 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
176 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
178 my $plugin = "Catalyst::Plugin::$_";
180 # Plugin caller should be our application class
181 eval "package $caller; require $plugin";
183 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
186 $caller->log->debug(qq/Loaded plugin "$plugin"/)
189 push @{"$caller\::ISA"}, $plugin;
195 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
196 if $ENV{CATALYST_ENGINE};
198 if ( $engine eq 'Catalyst::Engine::Server' ) {
199 $engine = 'Catalyst::Engine::HTTP::Daemon';
200 $caller->log->warn( "Catalyst::Engine::Server is deprecated, "
201 . "using Catalyst::Engine::HTTP::Daemon." );
205 die qq/Couldn't load engine "$engine", "$@"/ if $@;
208 push @{"$caller\::ISA"}, $engine;
210 $caller->engine($engine);
211 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
216 Contains the engine class.
220 Contains the logging object. Unless it is already set Catalyst sets this up with a
221 C<Catalyst::Log> object. To use your own log class:
223 $c->log( MyLogger->new );
224 $c->log->info("now logging with my own logger!");
226 Your log class should implement the methods described in the C<Catalyst::Log>
236 Join #catalyst on irc.perl.org.
240 http://lists.rawmode.org/mailman/listinfo/catalyst
241 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
245 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
246 L<Catalyst::Response>, L<Catalyst::Engine>
250 Sebastian Riedel, C<sri@oook.de>
254 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
255 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
256 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
257 and all the others who've helped.
261 This library is free software . You can redistribute it and/or modify it under
262 the same terms as perl itself.