4 use base qw[ Catalyst::Base Catalyst::Setup ];
5 use UNIVERSAL::require;
6 use Catalyst::Exception;
12 our $CATALYST_SCRIPT_GEN = 4;
14 our $VERSION = '5.24';
19 Catalyst - The Elegant MVC Web Application Framework
23 # use the helper to start a new application
27 # add models, views, controllers
28 script/myapp_create.pl model Something
29 script/myapp_create.pl view Stuff
30 script/myapp_create.pl controller Yada
33 script/myapp_server.pl
35 # command line interface
36 script/myapp_test.pl /yada
41 use Catalyst qw/My::Module My::OtherModule/;
43 use Catalyst '-Debug';
45 use Catalyst qw/-Debug -Engine=CGI/;
47 sub default : Private { $_[1]->res->output('Hello') } );
49 sub index : Path('/index.html') {
50 my ( $self, $c ) = @_;
51 $c->res->output('Hello');
55 sub product : Regex('^product[_]*(\d*).html$') {
56 my ( $self, $c ) = @_;
57 $c->stash->{template} = 'product.tt';
58 $c->stash->{product} = $c->req->snippets->[0];
61 See also L<Catalyst::Manual::Intro>
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 ( $class, @arguments ) = @_;
128 my $caller = caller(0);
130 if ( $caller eq 'main' ) {
134 # Prepare inheritance
135 unless ( $caller->isa($class) ) {
137 push @{"$caller\::ISA"}, $class;
140 if ( $caller->engine ) {
141 $caller->log->warn( qq/Attempt to re-initialize "$caller"/ );
148 foreach (@arguments) {
151 $flags->{log} = ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug';
153 elsif (/^-(\w+)=?(.*)$/) {
154 $flags->{ lc $1 } = $2;
157 push @{ $flags->{plugins} }, $_;
161 $caller->setup_log ( delete $flags->{log} );
162 $caller->setup_plugins ( delete $flags->{plugins} );
163 $caller->setup_dispatcher ( delete $flags->{dispatcher} );
164 $caller->setup_engine ( delete $flags->{engine} );
165 $caller->setup_home ( delete $flags->{home} );
167 for my $flag ( sort keys %{ $flags } ) {
169 if ( my $code = $caller->can( 'setup_' . $flag ) ) {
170 &$code( $caller, delete $flags->{$flag} );
173 $caller->log->warn(qq/Unknown flag "$flag"/);
177 $caller->log->warn( "You are running an old helper script! "
178 . "Please update your scripts by regenerating the "
179 . "application and copying over the new scripts." )
180 if ( $ENV{CATALYST_SCRIPT_GEN}
181 && ( $ENV{CATALYST_SCRIPT_GEN} < $CATALYST_SCRIPT_GEN ) );
184 if ( $caller->debug ) {
190 @plugins = grep { /^Catalyst::Plugin/ } @{"$caller\::ISA"};
194 my $t = Text::ASCIITable->new;
195 $t->setOptions( 'hide_HeadRow', 1 );
196 $t->setOptions( 'hide_HeadLine', 1 );
197 $t->setCols('Class');
198 $t->setColWidth( 'Class', 75, 1 );
199 $t->addRow($_) for @plugins;
200 $caller->log->debug( "Loaded plugins:\n" . $t->draw );
203 my $dispatcher = $caller->dispatcher;
204 my $engine = $caller->engine;
205 my $home = $caller->config->{home};
207 $caller->log->debug(qq/Loaded dispatcher "$dispatcher"/);
208 $caller->log->debug(qq/Loaded engine "$engine"/);
212 ? $caller->log->debug(qq/Found home "$home"/)
213 : $caller->log->debug(qq/Home "$home" doesn't exist/)
214 : $caller->log->debug(q/Couldn't find home/);
220 Contains the engine class.
224 Contains the logging object. Unless it is already set Catalyst sets this up with a
225 C<Catalyst::Log> object. To use your own log class:
227 $c->log( MyLogger->new );
228 $c->log->info("now logging with my own logger!");
230 Your log class should implement the methods described in the C<Catalyst::Log>
233 =item $c->plugin( $name, $class, @args )
235 Instant plugins for Catalyst.
236 Classdata accessor/mutator will be created, class loaded and instantiated.
238 MyApp->plugin( 'prototype', 'HTML::Prototype' );
240 $c->prototype->define_javascript_functions;
245 my ( $class, $name, $plugin, @args ) = @_;
248 if ( my $error = $UNIVERSAL::require::ERROR ) {
249 Catalyst::Exception->throw(
250 message => qq/Couldn't load instant plugin "$plugin", "$error"/
254 eval { $plugin->import };
255 $class->mk_classdata($name);
257 eval { $obj = $plugin->new(@args) };
260 Catalyst::Exception->throw(
261 message => qq/Couldn't instantiate instant plugin "$plugin", "$@"/
266 $class->log->debug(qq/Initialized instant plugin "$plugin" as "$name"/)
274 mod_perl2 support is considered experimental and may contain bugs.
280 Join #catalyst on irc.perl.org.
284 http://lists.rawmode.org/mailman/listinfo/catalyst
285 http://lists.rawmode.org/mailman/listinfo/catalyst-dev
289 http://catalyst.perl.org
295 =item L<Catalyst::Manual> - The Catalyst Manual
297 =item L<Catalyst::Engine> - Core Engine
299 =item L<Catalyst::Log> - The Log Class.
301 =item L<Catalyst::Request> - The Request Object
303 =item L<Catalyst::Response> - The Response Object
305 =item L<Catalyst::Test> - The test suite.
311 Sebastian Riedel, C<sri@oook.de>
315 Andy Grundman, Andrew Ford, Andrew Ruthven, Autrijus Tang, Christian Hansen,
316 Christopher Hicks, Dan Sully, Danijel Milicevic, David Naughton,
317 Gary Ashton Jones, Geoff Richards, Jesse Sheidlower, Jody Belka,
318 Johan Lindstrom, Juan Camacho, Leon Brocard, Marcus Ramberg,
319 Tatsuhiko Miyagawa and all the others who've helped.
323 This library is free software . You can redistribute it and/or modify it under
324 the same terms as perl itself.