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

Daniel McBrearty danielmcbrearty at gmail.com
Sun Aug 3 17:30:02 BST 2008


wait, it is on $self not $c, so my reservations don't really apply.

but what about reall config stuff that can change from one
installation to another? then you have to do $c->config->{my_var},
right?


On Sun, Aug 3, 2008 at 6:16 PM, Daniel McBrearty
<danielmcbrearty at gmail.com> wrote:
> (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));
>
> __PACKAGE__->config(
>  foo => 'default_for_foo',
>  bae => { default => 'for_bar' },
> );
>
> then later in your code just call $self->foo to get the runtime value.
> (/snip)
>
> 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
>
> cheers
>
> Daniel
>



-- 
There's an infinite supply of time, we just don't have it all yet.



More information about the Catalyst mailing list