__PACKAGE__->config( foo => 'bar' );
+ has foo => (
+ is => 'ro',
+ );
+
sub test {
my $self = shift;
- return $self->{foo};
+ return $self->foo;
}
sub forward_to_me {
my ( $self, $c ) = @_;
- $c->response->output( $self->{foo} );
+ $c->response->output( $self->foo );
}
1;
# Or just methods
print $c->comp('MyApp::Model::Something')->test;
- print $c->comp('MyApp::Model::Something')->{foo};
+ print $c->comp('MyApp::Model::Something')->foo;
=head1 DESCRIPTION
This is the universal base class for Catalyst components
(Model/View/Controller).
-It provides you with a generic new() for instantiation through Catalyst's
+It provides you with a generic new() for component construction through Catalyst's
component loader with config() support and a process() method placeholder.
+B<Note> that calling C<< $self->config >> inside a component is strongly
+not recommended - the correctly merged config should have already been
+passed to the constructor and stored in attributes - accessing
+the config accessor directly from an instance is likely to get the
+wrong values (as it only holds the class wide config, not things loaded
+from the config file!)
+
=cut
__PACKAGE__->mk_classdata('_plugins');
C<< __PACKAGE__->config >> hashref before calling C<< ->new >>
to instantiate the component.
-You can override it in your components to do custom instantiation, using
+You can override it in your components to do custom construction, using
something like this:
sub COMPONENT {
The component's config hash is merged with any config entry on the
application for this component and passed to C<new()> (as mentioned
-above at L</COMPONENT>). The common practice to access the merged
+above at L</COMPONENT>). The recommended practice to access the merged
config is to use a Moose attribute for each config entry on the
receiving component.