Commit | Line | Data |
fc7ec1d9 |
1 | package Catalyst::Base; |
2 | |
3 | use strict; |
4 | use base qw/Class::Data::Inheritable Class::Accessor::Fast/; |
5 | use NEXT; |
6 | |
7 | __PACKAGE__->mk_classdata('_config'); |
8 | |
9 | =head1 NAME |
10 | |
11 | Catalyst::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 | |
45 | This is the universal base class for Catalyst components |
46 | (Model/View/Controller). |
47 | |
48 | It provides you with a generic new() for instantiation through Catalyst's |
49 | component loader with config() support and a process() method placeholder. |
50 | |
51 | =head2 METHODS |
52 | |
748161c4 |
53 | =head3 new |
fc7ec1d9 |
54 | =cut |
55 | |
56 | sub new { |
57 | my ( $self, $c ) = @_; |
58 | return $self->NEXT::new( $self->config ); |
59 | } |
60 | |
61 | =head3 config |
62 | |
63 | =cut |
64 | |
65 | sub config { |
66 | my $self = shift; |
67 | $self->_config( {} ) unless $self->_config; |
68 | if ( $_[0] ) { |
69 | my $config = $_[1] ? {@_} : $_[0]; |
70 | while ( my ( $key, $val ) = each %$config ) { |
71 | $self->_config->{$key} = $val; |
72 | } |
73 | } |
74 | return $self->_config; |
75 | } |
76 | |
77 | =head3 process |
78 | |
79 | =cut |
80 | |
81 | sub process { 1 } |
82 | |
83 | =head1 SEE ALSO |
84 | |
85 | L<Catalyst>. |
86 | |
87 | =head1 AUTHOR |
88 | |
89 | Sebastian Riedel, C<sri@cpan.org> |
90 | |
91 | =head1 COPYRIGHT |
92 | |
93 | This program is free software, you can redistribute it and/or modify it under |
94 | the same terms as Perl itself. |
95 | |
96 | =cut |
97 | |
98 | 1; |