4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
9 __PACKAGE__->mk_classdata($_) for qw/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';
150 if ( $ENV{MOD_PERL} ) {
154 if ( $mod_perl::VERSION >= 1.99 ) {
155 $engine = 'Catalyst::Engine::Apache::MP2';
158 $engine = 'Catalyst::Engine::Apache::MP1';
165 next if $caller->debug;
167 *{"$caller\::debug"} = sub { 1 };
168 $caller->log->debug('Debug messages enabled');
170 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
171 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
173 my $plugin = "Catalyst::Plugin::$_";
178 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
181 push @plugins, " + $plugin";
183 push @{"$caller\::ISA"}, $plugin;
187 my $t = Text::ASCIITable->new;
188 $t->setCols('Class');
189 $t->addRow($_) for @plugins;
190 $caller->log->debug( 'Loaded plugins', $t->draw )
191 if ( @plugins && $caller->debug );
194 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
195 if $ENV{CATALYST_ENGINE};
198 die qq/Couldn't load engine "$engine", "$@"/ if $@;
201 push @{"$caller\::ISA"}, $engine;
203 $caller->engine($engine);
204 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
209 Contains the engine class.
213 Contains the logging object. Unless it is already set Catalyst sets this up with a
214 C<Catalyst::Log> object. To use your own log class:
216 $c->log( MyLogger->new );
217 $c->log->info("now logging with my own logger!");
219 Your log class should implement the methods described in the C<Catalyst::Log>
229 Join #catalyst on irc.perl.org.
233 http://lists.rawmode.org/mailman/listinfo/catalyst
234 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
238 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
239 L<Catalyst::Response>, L<Catalyst::Engine>
243 Sebastian Riedel, C<sri@oook.de>
247 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
248 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
249 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
250 and all the others who've helped.
254 This library is free software . You can redistribute it and/or modify it under
255 the same terms as perl itself.