[Catalyst] question for mst : using $c->config->{blah} ...

Daniel McBrearty danielmcbrearty at gmail.com
Sun Aug 3 17:16:54 BST 2008

(snip from another thread ...)

You should never, ever EVER access $self->config in a model, view or
controller object.

Your config value will be in $self->{key}.

It's considered normal to do

package My::Controller::Foo;

use strict;
use warnings;
use parent qw(Catalyst::Controller);

__PACKAGE__->mk_accessors(qw(foo bar));

 foo => 'default_for_foo',
 bae => { default => 'for_bar' },

then later in your code just call $self->foo to get the runtime value.

Why is that Matt?  I wasn't aware and have done it a fair bit. Not
hard to change, but I'd like to know why. Not really a big deal, but I
actually prefer the explicit use of config, for two reasons:

1. There is no chance of accidentally stomping on something else in $c namespace
2. It let;s you know where to go look for that particular bit of $c
later in you need to



More information about the Catalyst mailing list