1 package Catalyst::Base;
4 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
8 __PACKAGE__->mk_classdata($_) for qw/_attrcache _cache _config/;
9 __PACKAGE__->_attrcache( {} );
10 __PACKAGE__->_cache( [] );
12 # note - see attributes(3pm)
13 sub MODIFY_CODE_ATTRIBUTES {
14 my ( $class, $code, @attrs ) = @_;
15 $class->_attrcache->{$code} = [@attrs];
16 push @{ $class->_cache }, [ $code, [@attrs] ];
20 sub FETCH_CODE_ATTRIBUTES { $_[0]->_attrcache->{ $_[1] } || () }
24 Catalyst::Base - Catalyst Universal Base Class
28 # lib/MyApp/Model/Something.pm
29 package MyApp::Model::Something;
31 use base 'Catalyst::Base';
33 __PACKAGE__->config( foo => 'bar' );
41 my ( $self, $c ) = @_;
42 $c->response->output( $self->{foo} );
47 # Methods can be a request step
48 $c->forward(qw/MyApp::Model::Something forward_to_me/);
51 print $c->comp('MyApp::Model::Something')->test;
53 print $c->comp('MyApp::Model::Something')->{foo};
57 This is the universal base class for Catalyst components
58 (Model/View/Controller).
60 It provides you with a generic new() for instantiation through Catalyst's
61 component loader with config() support and a process() method placeholder.
72 my ( $self, $c ) = @_;
73 my $class = ref $self || $self;
74 my $appname = Catalyst::Utils::class2appclass($class);
75 my $suffix = Catalyst::Utils::class2classsuffix($class);
76 my $appconfig = $appname->config->{$suffix} || {};
77 my $config = { %{ $self->config }, %{$appconfig} };
78 return $self->NEXT::new($config);
81 # remember to leave blank lines between the consecutive =item's
82 # otherwise the pod tools don't recognize the subsequent =items
86 =item $c->config($hashref)
88 =item $c->config($key, $value, ...)
94 $self->_config( {} ) unless $self->_config;
96 my $config = $_[1] ? {@_} : $_[0];
97 while ( my ( $key, $val ) = each %$config ) {
98 $self->_config->{$key} = $val;
101 return $self->_config;
109 die( ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process" );
120 Sebastian Riedel, C<sri@cpan.org>
121 Marcus Ramberg, C<mramberg@cpan.org>
125 This program is free software, you can redistribute it and/or modify it under
126 the same terms as Perl itself.