From: Tomas Doran Date: Fri, 9 Mar 2012 08:15:40 +0000 (+0000) Subject: Doc fixes / additions in Catalyst::Component X-Git-Tag: 5.90012~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d8ccdd9d64915be00c29a7ab21d9275431235697 Doc fixes / additions in Catalyst::Component --- diff --git a/Changes b/Changes index 73145bc..5135713 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ # This file documents the revision history for Perl extension Catalyst. + Documentation: + - Fix documentation in Catalyst::Component to show attributes and + calling readers, rather than accessing elements in the $self->{} hash + directly. + - Add note in Catalyst::Component to strongly disrecommend $self->config + 5.90011 - 2012-03-08 16:43:00 Bug fixes: diff --git a/lib/Catalyst/Component.pm b/lib/Catalyst/Component.pm index 101f29c..1b494a2 100644 --- a/lib/Catalyst/Component.pm +++ b/lib/Catalyst/Component.pm @@ -28,14 +28,18 @@ Catalyst::Component - Catalyst Component Base Class __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; @@ -46,7 +50,7 @@ Catalyst::Component - Catalyst Component Base Class # 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 @@ -56,6 +60,13 @@ This is the universal base class for Catalyst components It provides you with a generic new() for component construction through Catalyst's component loader with config() support and a process() method placeholder. +B that calling C<< $self->config >> inside a component is strongly +disrecommended - 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'); @@ -202,7 +213,7 @@ a Catalyst application has its own config hash. The component's config hash is merged with any config entry on the application for this component and passed to C (as mentioned -above at L). The common practice to access the merged +above at L). The recommended practice to access the merged config is to use a Moose attribute for each config entry on the receiving component.