1 package Catalyst::Base;
4 use base qw/Catalyst::AttrContainer Class::Accessor::Fast/;
6 use Catalyst::Exception;
9 __PACKAGE__->mk_classdata($_) for qw/_config/;
11 sub _DISPATCH :Private {
12 my ( $self, $c ) = @_;
13 my @containers = $c->dispatcher->get_containers( $c->namespace );
15 foreach my $name (qw/begin auto end/) {
17 # Go down the container list representing each part of the
18 # current namespace inheritance tree, grabbing the actions hash
19 # of the ActionContainer object and looking for actions of the
20 # appropriate name registered to the namespace
24 grep { exists $_->{$name} }
25 map { $_->actions } @containers
29 # Errors break the normal flow and the end action is instantly run
34 if ( my $begin = @{ $actions{begin} }[-1] ) {
36 $error++ if scalar @{ $c->error };
39 # Execute the auto chain
41 for my $auto ( @{ $actions{auto} } ) {
45 $error++ if scalar @{ $c->error };
46 last unless $c->state;
49 # Execute the action or last default
50 my $mkay = $autorun ? $c->state ? 1 : 0 : 1;
53 $c->action->execute($c);
54 $error++ if scalar @{ $c->error };
59 if ( my $end = @{ $actions{end} }[-1] ) {
66 Catalyst::Base - Catalyst Universal Base Class
70 # lib/MyApp/Model/Something.pm
71 package MyApp::Model::Something;
73 use base 'Catalyst::Base';
75 __PACKAGE__->config( foo => 'bar' );
83 my ( $self, $c ) = @_;
84 $c->response->output( $self->{foo} );
89 # Methods can be a request step
90 $c->forward(qw/MyApp::Model::Something forward_to_me/);
93 print $c->comp('MyApp::Model::Something')->test;
95 print $c->comp('MyApp::Model::Something')->{foo};
99 This is the universal base class for Catalyst components
100 (Model/View/Controller).
102 It provides you with a generic new() for instantiation through Catalyst's
103 component loader with config() support and a process() method placeholder.
114 my ( $self, $c ) = @_;
116 # Temporary fix, some components does not pass context to constructor
117 my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {};
119 return $self->NEXT::new( { %{ $self->config }, %{ $arguments } } );
122 # remember to leave blank lines between the consecutive =item's
123 # otherwise the pod tools don't recognize the subsequent =items
127 =item $c->config($hashref)
129 =item $c->config($key, $value, ...)
135 $self->_config( {} ) unless $self->_config;
137 my $config = @_ > 1 ? {@_} : $_[0];
138 while ( my ( $key, $val ) = each %$config ) {
139 $self->_config->{$key} = $val;
142 return $self->_config;
151 Catalyst::Exception->throw(
152 message => ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process"
156 =item FETCH_CODE_ATTRIBUTES
158 =item MODIFY_CODE_ATTRIBUTES
168 Sebastian Riedel, C<sri@cpan.org>
169 Marcus Ramberg, C<mramberg@cpan.org>
170 Matt S Trout, C<mst@shadowcatsystems.co.uk>
174 This program is free software, you can redistribute it and/or modify it under
175 the same terms as Perl itself.