4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
8 __PACKAGE__->mk_classdata($_) for qw/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 sub default : Private { $_[1]->res->output('Hello') } );
45 sub index : Absolute('index.html') {
46 my ( $self, $c ) = @_;
47 $c->res->output('Hello');
51 sub product : Regex('/^product[_]*(\d*).html$/') {
52 my ( $self, $c ) = @_;
53 $c->stash->{template} = 'product.tt';
54 $c->stash->{product} = $c->req->snippets->[0];
57 See also L<Catalyst::Manual::Intro>
61 Catalyst is based upon L<Maypole>, which you should consider for smaller
64 The key concept of Catalyst is DRY (Don't Repeat Yourself).
66 See L<Catalyst::Manual> for more documentation.
68 Catalyst plugins can be loaded by naming them as arguments to the "use Catalyst" statement.
69 Omit the C<Catalyst::Plugin::> prefix from the plugin name,
70 so C<Catalyst::Plugin::My::Module> becomes C<My::Module>.
72 use Catalyst 'My::Module';
74 Special flags like -Debug and -Engine can also be specifed as arguments when
77 use Catalyst qw/-Debug My::Module/;
79 The position of plugins and flags in the chain is important, because they are
80 loaded in exactly the order that they appear.
82 The following flags are supported:
88 enables debug output, i.e.:
90 use Catalyst '-Debug';
92 this is equivalent to:
99 Force Catalyst to use a specific engine.
100 Omit the C<Catalyst::Engine::> prefix of the engine name, i.e.:
102 use Catalyst '-Engine=CGI';
112 Overload to enable debug messages.
120 Returns a hashref containing your applications settings.
125 my ( $self, @options ) = @_;
126 my $caller = caller(0);
128 unless ( $caller->isa($self) ) {
130 push @{"$caller\::ISA"}, $self;
133 if ( $caller->engine ) {
134 return; # Catalyst is allready initialized
137 unless ( $caller->log ) {
138 $caller->log( Catalyst::Log->new );
141 if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($caller) . '_DEBUG' } ) {
143 *{"$caller\::debug"} = sub { 1 };
144 $caller->log->debug('Debug messages enabled');
150 ? 'Catalyst::Engine::Apache'
151 : 'Catalyst::Engine::CGI';
155 next if $caller->debug;
157 *{"$caller\::debug"} = sub { 1 };
158 $caller->log->debug('Debug messages enabled');
160 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
161 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
163 my $plugin = "Catalyst::Plugin::$_";
165 # Plugin caller should be our application class
166 eval "package $caller; require $plugin";
168 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
171 $caller->log->debug(qq/Loaded plugin "$plugin"/)
174 push @{"$caller\::ISA"}, $plugin;
180 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
181 if $ENV{CATALYST_ENGINE};
183 if ( $engine eq 'Catalyst::Engine::Server' ) {
184 $engine = 'Catalyst::Engine::HTTP::Daemon';
185 $caller->log->warn( "Catalyst::Engine::Server is deprecated, "
186 . "using Catalyst::Engine::HTTP::Daemon." );
190 die qq/Couldn't load engine "$engine", "$@"/ if $@;
193 push @{"$caller\::ISA"}, $engine;
195 $caller->engine($engine);
196 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
201 Contains the engine class.
205 Contains the logging object. Unless it is already set Catalyst sets this up with a
206 C<Catalyst::Log> object. To use your own log class:
208 $c->log( MyLogger->new );
209 $c->log->info("now logging with my own logger!");
211 Your log class should implement the methods described in the C<Catalyst::Log>
221 Join #catalyst on irc.perl.org.
225 http://lists.rawmode.org/mailman/listinfo/catalyst
226 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
230 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
231 L<Catalyst::Response>, L<Catalyst::Engine>
235 Sebastian Riedel, C<sri@oook.de>
239 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
240 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
241 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
242 and all the others who've helped.
246 This library is free software . You can redistribute it and/or modify it under
247 the same terms as perl itself.