1 package Catalyst::Base;
4 use base qw/Catalyst::AttrContainer Class::Accessor::Fast/;
6 use Catalyst::Exception;
9 __PACKAGE__->mk_classdata($_) for qw/_config _dispatch_steps/;
11 __PACKAGE__->_dispatch_steps([ qw/_BEGIN _AUTO _ACTION/ ]);
13 sub _DISPATCH :Private {
14 my ( $self, $c ) = @_;
16 foreach my $disp (@{$self->_dispatch_steps}) {
17 last unless $c->forward($disp);
24 my ( $self, $c ) = @_;
25 my $begin = @{ $c->get_action('begin', $c->namespace, 1) }[-1];
26 return 1 unless $begin;
27 $begin->[0]->execute($c);
32 my ( $self, $c ) = @_;
33 my @auto = @{ $c->get_action('auto', $c->namespace, 1) };
34 foreach my $auto (@auto) {
35 $auto->[0]->execute($c);
36 return 0 unless $c->state;
41 sub _ACTION :Private {
42 my ( $self, $c ) = @_;
43 $c->action->execute($c);
48 my ( $self, $c ) = @_;
49 my $end = @{ $c->get_action('end', $c->namespace, 1) }[-1];
51 $end->[0]->execute($c);
57 Catalyst::Base - Catalyst Universal Base Class
61 # lib/MyApp/Model/Something.pm
62 package MyApp::Model::Something;
64 use base 'Catalyst::Base';
66 __PACKAGE__->config( foo => 'bar' );
74 my ( $self, $c ) = @_;
75 $c->response->output( $self->{foo} );
80 # Methods can be a request step
81 $c->forward(qw/MyApp::Model::Something forward_to_me/);
84 print $c->comp('MyApp::Model::Something')->test;
86 print $c->comp('MyApp::Model::Something')->{foo};
90 This is the universal base class for Catalyst components
91 (Model/View/Controller).
93 It provides you with a generic new() for instantiation through Catalyst's
94 component loader with config() support and a process() method placeholder.
105 my ( $self, $c ) = @_;
107 # Temporary fix, some components does not pass context to constructor
108 my $arguments = ( ref( $_[-1] ) eq 'HASH' ) ? $_[-1] : {};
110 return $self->NEXT::new( { %{ $self->config }, %{ $arguments } } );
113 # remember to leave blank lines between the consecutive =item's
114 # otherwise the pod tools don't recognize the subsequent =items
118 =item $c->config($hashref)
120 =item $c->config($key, $value, ...)
126 $self->_config( {} ) unless $self->_config;
128 my $config = @_ > 1 ? {@_} : $_[0];
129 while ( my ( $key, $val ) = each %$config ) {
130 $self->_config->{$key} = $val;
133 return $self->_config;
142 Catalyst::Exception->throw(
143 message => ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process"
147 =item FETCH_CODE_ATTRIBUTES
149 =item MODIFY_CODE_ATTRIBUTES
159 Sebastian Riedel, C<sri@cpan.org>
160 Marcus Ramberg, C<mramberg@cpan.org>
161 Matt S Trout, C<mst@shadowcatsystems.co.uk>
165 This program is free software, you can redistribute it and/or modify it under
166 the same terms as Perl itself.