1Catalyst::Component(3)User Contributed Perl DocumentationCatalyst::Component(3)
2
3
4

NAME

6       Catalyst::Component - Catalyst Component Base Class
7

SYNOPSIS

9           # lib/MyApp/Model/Something.pm
10           package MyApp::Model::Something;
11
12           use base 'Catalyst::Component';
13
14           __PACKAGE__->config( foo => 'bar' );
15
16           sub test {
17               my $self = shift;
18               return $self->{foo};
19           }
20
21           sub forward_to_me {
22               my ( $self, $c ) = @_;
23               $c->response->output( $self->{foo} );
24           }
25
26           1;
27
28           # Methods can be a request step
29           $c->forward(qw/MyApp::Model::Something forward_to_me/);
30
31           # Or just methods
32           print $c->comp('MyApp::Model::Something')->test;
33
34           print $c->comp('MyApp::Model::Something')->{foo};
35

DESCRIPTION

37       This is the universal base class for Catalyst components
38       (Model/View/Controller).
39
40       It provides you with a generic new() for instantiation through Cata‐
41       lyst's component loader with config() support and a process() method
42       placeholder.
43

METHODS

45       new($c, $arguments)
46
47       Called by COMPONENT to instantiate the component; should return an
48       object to be stored in the application's component hash.
49
50       COMPONENT($c, $arguments)
51
52       If this method is present (as it is on all Catalyst::Component sub‐
53       classes, it is called by Catalyst during setup_components with the
54       application class as $c and any config entry on the application for
55       this component (for example, in the case of MyApp::Controller::Foo this
56       would be MyApp->config->{'Controller::Foo'}). The arguments are
57       expected to be a hashref and are merged with the __PACKAGE__->config
58       hashref before calling ->new to instantiate the component.
59
60       $c->config
61
62       $c->config($hashref)
63
64       $c->config($key, $value, ...)
65
66       Accessor for this component's config hash. Config values can be set as
67       key value pair, or you can specify a hashref. In either case the keys
68       will be merged with any existing config settings. Each component in a
69       Catalyst application has it's own config hash.
70
71       $c->process()
72
73       This is the default method called on a Catalyst component in the dis‐
74       patcher.  For instance, Views implement this action to render the
75       response body when you forward to them. The default is an abstract
76       method.
77
78       $c->merge_config_hashes( $hashref, $hashref )
79
80       Merges two hashes together recursively, giving right-hand precedence.
81       Alias for the method in Catalyst::Utils.
82

OPTIONAL METHODS

84       ACCEPT_CONTEXT($c, @args)
85
86       Catalyst components are normally initalized during server startup,
87       either as a Class or a Instance. However, some components require
88       information about the current request. To do so, they can implement an
89       ACCEPT_CONTEXT method.
90
91       If this method is present, it is called during $c->comp/con‐
92       troller/model/view with the current $c and any additional args (e.g.
93       $c->model('Foo', qw/bar baz/) would cause your MyApp::Model::Foo
94       instance's ACCEPT_CONTEXT to be called with ($c, 'bar', 'baz')) and the
95       return value of this method is returned to the calling code in the
96       application rather than the component itself.
97

SEE ALSO

99       Catalyst, Catalyst::Model, Catalyst::View, Catalyst::Controller.
100

AUTHOR

102       Sebastian Riedel, "sri@cpan.org" Marcus Ramberg, "mramberg@cpan.org"
103       Matt S Trout, "mst@shadowcatsystems.co.uk"
104
106       This program is free software, you can redistribute it and/or modify it
107       under the same terms as Perl itself.
108
109
110
111perl v5.8.8                       2007-09-20            Catalyst::Component(3)
Impressum