doc patch from Andrew Ford
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Base.pm
CommitLineData
fc7ec1d9 1package Catalyst::Base;
2
3use strict;
4use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
5use NEXT;
6
7__PACKAGE__->mk_classdata('_config');
8
9=head1 NAME
10
11Catalyst::Base - Catalyst Universal Base Class
12
13=head1 SYNOPSIS
14
15 # lib/MyApp/Model/Something.pm
16 package MyApp::Model::Something;
17
18 use base 'Catalyst::Base';
19
20 __PACKAGE__->config( foo => 'bar' );
21
22 sub test {
23 my $self = shift;
24 return $self->{foo};
25 }
26
27 sub forward_to_me {
28 my ( $self, $c ) = @_;
29 $c->response->output( $self->{foo} );
30 }
31
32 1;
33
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 );
37
38 # Or just methods
39 print $c->comp('MyApp::Model::Something')->test;
40
41 print $c->comp('MyApp::Model::Something')->{foo};
42
43=head1 DESCRIPTION
44
45This is the universal base class for Catalyst components
46(Model/View/Controller).
47
48It provides you with a generic new() for instantiation through Catalyst's
49component loader with config() support and a process() method placeholder.
50
23f9d934 51=head1 METHODS
52
53=over 4
54
55=item new($c)
fc7ec1d9 56
57=cut
58
59sub new {
60 my ( $self, $c ) = @_;
61 return $self->NEXT::new( $self->config );
62}
63
23f9d934 64# remember to leave blank lines between the consecutive =item's
65# otherwise the pod tools don't recognize the subsequent =items
66
67=item $c->config
68
69=item $c->config($hashref)
70
71=item $c->config($key, $value, ...)
fc7ec1d9 72
73=cut
74
75sub config {
76 my $self = shift;
77 $self->_config( {} ) unless $self->_config;
78 if ( $_[0] ) {
79 my $config = $_[1] ? {@_} : $_[0];
80 while ( my ( $key, $val ) = each %$config ) {
81 $self->_config->{$key} = $val;
82 }
83 }
84 return $self->_config;
85}
86
23f9d934 87=item $c->process()
fc7ec1d9 88
89=cut
90
91sub process { 1 }
92
93=head1 SEE ALSO
94
95L<Catalyst>.
96
97=head1 AUTHOR
98
99Sebastian Riedel, C<sri@cpan.org>
100
101=head1 COPYRIGHT
102
103This program is free software, you can redistribute it and/or modify it under
104the same terms as Perl itself.
105
106=cut
107
1081;