1 package Catalyst::Base;
4 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
7 __PACKAGE__->mk_classdata($_) for qw/_cache _config/;
8 __PACKAGE__->_cache( [] );
10 sub MODIFY_CODE_ATTRIBUTES {
11 my ( $class, $code, @attrs ) = @_;
12 push @{ $class->_cache }, [ $code, [@attrs] ];
18 Catalyst::Base - Catalyst Universal Base Class
22 # lib/MyApp/Model/Something.pm
23 package MyApp::Model::Something;
25 use base 'Catalyst::Base';
27 __PACKAGE__->config( foo => 'bar' );
35 my ( $self, $c ) = @_;
36 $c->response->output( $self->{foo} );
41 # Methods can be a request step
42 $c->forward(qw/MyApp::Model::Something forward_to_me/);
43 MyApp->action( 'index.html' => \&MyApp::Model::Something::forward_to_me );
46 print $c->comp('MyApp::Model::Something')->test;
48 print $c->comp('MyApp::Model::Something')->{foo};
52 This is the universal base class for Catalyst components
53 (Model/View/Controller).
55 It provides you with a generic new() for instantiation through Catalyst's
56 component loader with config() support and a process() method placeholder.
67 my ( $self, $c ) = @_;
68 return $self->NEXT::new( $self->config );
71 # remember to leave blank lines between the consecutive =item's
72 # otherwise the pod tools don't recognize the subsequent =items
76 =item $c->config($hashref)
78 =item $c->config($key, $value, ...)
84 $self->_config( {} ) unless $self->_config;
86 my $config = $_[1] ? {@_} : $_[0];
87 while ( my ( $key, $val ) = each %$config ) {
88 $self->_config->{$key} = $val;
91 return $self->_config;
108 Sebastian Riedel, C<sri@cpan.org>
112 This program is free software, you can redistribute it and/or modify it under
113 the same terms as Perl itself.