[Catalyst] Setting config after setup has been run is not allowed.

John Napiorkowski jjn1056 at yahoo.com
Mon Sep 28 16:19:42 GMT 2015


You shouldn't try to change the configuration once setup if finished since at that point everything has been initialized.  if you change stuff there its not going to do anything.  Whats the actual use case you are trying to achieve here.
FWIW Calling $c->config for application scoped stuff is ok I believe (no change, just getting the data).  For example if I really need to do a plugin, I usually do like:
my $adaptor_namespace = sub {  my $app = shift;  if(my $config = $app->config->{'Plugin::InjectionHelpers'}) {    my $namespace = $config->{adaptor_namespace};    return $namespace if $namespace;  }  return 'Catalyst::Model::InjectionHelpers';};
to create a way for the plugin to have stuff in the config.  In this case I also created an anonymous code ref instead of a normal method so that the plugin would not pollute the application namespace so much. 


     On Friday, September 25, 2015 8:40 AM, Bill Moseley <moseley at hank.org> wrote:
   

 I'm confused about this rather stern note in Catalyst.pm.
Is this the following wrapper related to the text in the NOTE?

B<NOTE:> you MUST NOT call C<< $self->config >> or C<< __PACKAGE__->config >>as a way of reading config within your code, as this B<will not> give you thecorrectly merged config back. You B<MUST> take the config values supplied tothe constructor and use those instead.
=cut
around config => sub {    my $orig = shift;    my $c = shift;
    croak('Setting config after setup has been run is not allowed.')        if ( @_ and $c->setup_finished );
    $c->$orig(@_);};

I understand the NOTE for Model/View/Controllers where the component's __PACKAGE__->config is merged in with the application config for that component.   Calling $self->config won't be the same thing passed to the component's constructor.
But, what's the issue with calling $c->config( foo => 123 ) at runtime?   Or even $c->config( \%new_config )?   
Note that wrapper only applies to calling config on the app class, and does not apply to Model/View/Controllers.
Is there some other issues I'm missing?   What problem is that wrapper trying to prevent?
Thanks,

-- 
Bill Moseley
moseley at hank.org
_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/catalyst/attachments/20150928/ac9d9c65/attachment.htm>


More information about the Catalyst mailing list