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 # note - see attributes(3pm)
11 sub MODIFY_CODE_ATTRIBUTES {
12 my ( $class, $code, @attrs ) = @_;
13 push @{ $class->_cache }, [ $code, [@attrs] ];
19 Catalyst::Base - Catalyst Universal Base Class
23 # lib/MyApp/Model/Something.pm
24 package MyApp::Model::Something;
26 use base 'Catalyst::Base';
28 __PACKAGE__->config( foo => 'bar' );
36 my ( $self, $c ) = @_;
37 $c->response->output( $self->{foo} );
42 # Methods can be a request step
43 $c->forward(qw/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;
98 sub process { die ((ref $_[0] || $_[0])." did not override Catalyst::Base::process"); }
108 Sebastian Riedel, C<sri@cpan.org>
109 Marcus Ramberg, C<mramberg@cpan.org>
113 This program is free software, you can redistribute it and/or modify it under
114 the same terms as Perl itself.