1 package Catalyst::Base;
4 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
7 __PACKAGE__->mk_classdata('_config');
11 Catalyst::Base - Catalyst Universal Base Class
15 # lib/MyApp/Model/Something.pm
16 package MyApp::Model::Something;
18 use base 'Catalyst::Base';
20 __PACKAGE__->config( foo => 'bar' );
28 my ( $self, $c ) = @_;
29 $c->response->output( $self->{foo} );
34 # Methods can be a request step
35 $c->forward(qw/MyApp::Model::Something forward_to_me/);
36 MyApp->action( 'index.html' => \&MyApp::Model::Something::forward_to_me );
39 print $c->comp('MyApp::Model::Something')->test;
41 print $c->comp('MyApp::Model::Something')->{foo};
45 This is the universal base class for Catalyst components
46 (Model/View/Controller).
48 It provides you with a generic new() for instantiation through Catalyst's
49 component loader with config() support and a process() method placeholder.
60 my ( $self, $c ) = @_;
61 return $self->NEXT::new( $self->config );
64 # remember to leave blank lines between the consecutive =item's
65 # otherwise the pod tools don't recognize the subsequent =items
69 =item $c->config($hashref)
71 =item $c->config($key, $value, ...)
77 $self->_config( {} ) unless $self->_config;
79 my $config = $_[1] ? {@_} : $_[0];
80 while ( my ( $key, $val ) = each %$config ) {
81 $self->_config->{$key} = $val;
84 return $self->_config;
99 Sebastian Riedel, C<sri@cpan.org>
103 This program is free software, you can redistribute it and/or modify it under
104 the same terms as Perl itself.