4 use base 'Catalyst::Base';
5 use UNIVERSAL::require;
8 use Text::ASCIITable::Wrap 'wrap';
10 __PACKAGE__->mk_classdata($_) for qw/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';
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 (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
172 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
174 my $plugin = "Catalyst::Plugin::$_";
179 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
182 push @plugins, $plugin;
184 push @{"$caller\::ISA"}, $plugin;
188 my $t = Text::ASCIITable->new( { hide_HeadRow => 1, hide_HeadLine => 1 } );
189 $t->setCols('Class');
190 $t->setColWidth( 'Class', 75, 1 );
191 $t->addRow( wrap( $_, 75 ) ) for @plugins;
192 $caller->log->debug( 'Loaded plugins', $t->draw )
193 if ( @plugins && $caller->debug );
196 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
197 if $ENV{CATALYST_ENGINE};
200 die qq/Couldn't load engine "$engine", "$@"/ if $@;
203 push @{"$caller\::ISA"}, $engine;
205 $caller->engine($engine);
206 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
211 Contains the engine class.
215 Contains the logging object. Unless it is already set Catalyst sets this up with a
216 C<Catalyst::Log> object. To use your own log class:
218 $c->log( MyLogger->new );
219 $c->log->info("now logging with my own logger!");
221 Your log class should implement the methods described in the C<Catalyst::Log>
231 Join #catalyst on irc.perl.org.
235 http://lists.rawmode.org/mailman/listinfo/catalyst
236 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
240 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
241 L<Catalyst::Response>, L<Catalyst::Engine>
245 Sebastian Riedel, C<sri@oook.de>
249 Andrew Ford, Andrew Ruthven, Christian Hansen, Christopher Hicks,
250 Dan Sully, Danijel Milicevic, David Naughton, Gary Ashton Jones,
251 Jesse Sheidlower, Johan Lindstrom, Marcus Ramberg, Tatsuhiko Miyagawa
252 and all the others who've helped.
256 This library is free software . You can redistribute it and/or modify it under
257 the same terms as perl itself.