1 package Catalyst::Base;
4 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
7 __PACKAGE__->mk_classdata($_) for qw/_attrcache _cache _config/;
8 __PACKAGE__->_cache( [] );
9 __PACKAGE__->_attrcache( {} );
11 # note - see attributes(3pm)
12 sub MODIFY_CODE_ATTRIBUTES {
13 my ( $class, $code, @attrs ) = @_;
14 $class->_attrcache->{$code} = [@attrs];
15 push @{ $class->_cache }, [ $code, [@attrs] ];
19 sub FETCH_CODE_ATTRIBUTES { $_[0]->_attrcache->{ $_[1] } || () }
23 Catalyst::Base - Catalyst Universal Base Class
27 # lib/MyApp/Model/Something.pm
28 package MyApp::Model::Something;
30 use base 'Catalyst::Base';
32 __PACKAGE__->config( foo => 'bar' );
40 my ( $self, $c ) = @_;
41 $c->response->output( $self->{foo} );
46 # Methods can be a request step
47 $c->forward(qw/MyApp::Model::Something forward_to_me/);
50 print $c->comp('MyApp::Model::Something')->test;
52 print $c->comp('MyApp::Model::Something')->{foo};
56 This is the universal base class for Catalyst components
57 (Model/View/Controller).
59 It provides you with a generic new() for instantiation through Catalyst's
60 component loader with config() support and a process() method placeholder.
71 my ( $self, $c ) = @_;
72 return $self->NEXT::new( $self->config );
75 # remember to leave blank lines between the consecutive =item's
76 # otherwise the pod tools don't recognize the subsequent =items
80 =item $c->config($hashref)
82 =item $c->config($key, $value, ...)
88 $self->_config( {} ) unless $self->_config;
90 my $config = $_[1] ? {@_} : $_[0];
91 while ( my ( $key, $val ) = each %$config ) {
92 $self->_config->{$key} = $val;
95 return $self->_config;
103 die( ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process" );
114 Sebastian Riedel, C<sri@cpan.org>
115 Marcus Ramberg, C<mramberg@cpan.org>
119 This program is free software, you can redistribute it and/or modify it under
120 the same terms as Perl itself.