4 use base 'Class::Data::Inheritable';
5 use UNIVERSAL::require;
8 __PACKAGE__->mk_classdata($_) for qw/_config log/;
10 our $VERSION = '4.23';
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
35 See also L<Catalyst::Manual::Intro>
40 use Catalyst qw/My::Module My::OtherModule/;
42 use Catalyst '-Debug';
44 use Catalyst qw/-Debug -Engine=CGI/;
46 __PACKAGE__->action( '!default' => sub { $_[1]->res->output('Hello') } );
50 my ( $self, $c ) = @_;
51 $c->res->output('Hello');
57 '/^product[_]*(\d*).html$/' => sub {
58 my ( $self, $c ) = @_;
59 $c->stash->{template} = 'product.tt';
60 $c->stash->{product} = $c->req->snippets->[0];
66 Catalyst is based upon L<Maypole>, which you should consider for smaller
69 The key concept of Catalyst is DRY (Don't Repeat Yourself).
71 See L<Catalyst::Manual> for more documentation.
73 Omit the Catalyst::Plugin:: prefix from plugins.
74 So Catalyst::Plugin::My::Module becomes My::Module.
76 use Catalyst 'My::Module';
78 You can also set special flags like -Debug and -Engine.
80 use Catalyst qw/-Debug My::Module/;
82 The position of plugins and flags in the chain is important,
83 because they are loaded in the same order they appear.
87 use Catalyst '-Debug';
96 Force Catalyst to use a specific engine.
97 Omit the Catalyst::Engine:: prefix.
99 use Catalyst '-Engine=CGI';
105 Overload to enable debug messages.
113 Returns a hashref containing your applications settings.
119 $self->_config( {} ) unless $self->_config;
121 my $config = $_[1] ? {@_} : $_[0];
122 while ( my ( $key, $val ) = each %$config ) {
123 $self->_config->{$key} = $val;
126 return $self->_config;
130 my ( $self, @options ) = @_;
131 my $caller = caller(0);
136 *{"$caller\::handler"} =
137 sub { Catalyst::Engine::handler( $caller, @_ ) };
138 push @{"$caller\::ISA"}, $self;
140 $self->log( Catalyst::Log->new );
144 $ENV{MOD_PERL} ? 'Catalyst::Engine::Apache' : 'Catalyst::Engine::CGI';
149 *{"$self\::debug"} = sub { 1 };
150 $caller->log->debug('Debug messages enabled');
152 elsif (/^-Engine=(.*)$/) { $engine = "Catalyst::Engine::$1" }
153 elsif (/^-.*$/) { $caller->log->error(qq/Unknown flag "$_"/) }
155 my $plugin = "Catalyst::Plugin::$_";
157 # Plugin caller should be our application class
158 eval "package $caller; require $plugin";
160 $caller->log->error(qq/Couldn't load plugin "$plugin", "$@"/);
163 $caller->log->debug(qq/Loaded plugin "$plugin"/)
165 unshift @ISA, $plugin;
171 $engine = "Catalyst::Engine::$ENV{CATALYST_ENGINE}"
172 if $ENV{CATALYST_ENGINE};
174 die qq/Couldn't load engine "$engine", "$@"/ if $@;
176 $caller->log->debug(qq/Loaded engine "$engine"/) if $caller->debug;
181 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
182 L<Catalyst::Response>, L<Catalyst::Engine>
186 Sebastian Riedel, C<sri@oook.de>
190 Danijel Milicevic, David Naughton, Gary Ashton Jones, Jesse Sheidlower,
191 Johan Lindstrom, Marcus Ramberg and all the others who've helped.
195 This library is free software . You can redistribute it and/or modify it under
196 the same terms as perl itself.