Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Catalyst component config

by Solo (Deacon)
on Aug 25, 2011 at 11:41 UTC ( #922317=perlquestion: print w/replies, xml ) Need Help??

Solo has asked for the wisdom of the Perl Monks concerning the following question:

Looking at the Component configuration section in the Catalyst::Manual::ExtendingCatalyst POD, I see I should be able to access my component's config with $self->config. However, that's empty. Here's my setup, including variations I've tried.

package MyApp::Controller::Foo; use Data::Dumper; ... sub auto { my( $self, $c ) = @_; $c->log->debug( Dumper(__PACKAGE__->config) ); # yields { } $c->log->debug( Dumper($self->config) ); # yields { } (metho +d I think I should work per doc) $c->log->debug( Dumper($c->config) ); # the whole config +tree, not just this component's #$c->config->{'Controller::Foo'}->... # the only way I've figured +out to access local config (fixed typo) } # MyApp.conf variation 1 name MyAPP <Controller Foo> foo bar </Controller> # MyApp.conf variation 2 -- no difference in results from 1 name MyApp <MyApp> <Controller Foo> foo bar </Controller> </MyApp>

What am I doing wrong? Or, if I'm looking at the wrong docs, which should I be looking at?

Replies are listed 'Best First'.
Re: Catalyst component config
by Solo (Deacon) on Aug 26, 2011 at 02:01 UTC

    Again, the fine folks on #catalyst have helped my understanding. First off, what I'm trying to do is pretty wrong.

    Instead of using $c->config, you just need to know that config values are rolled into the object hash during instantiation. So, $self->{foo} contains the config value. (Namespace collisions seem possible, and are on my list to investigate).

    # in myapp.conf <Controller Foo> foo bar </Controller> # to use config in package MyApp::Controller::Foo; ... sub baz { my ($self, $c) = @_; # data from config $c->log->debug( $self->{foo} ); # logs 'bar' }

    Optionally, with Moose accessors as suggested in the POD. (And I don't know much about Moose, so this may not be the best way.)

    package MyApp::Controller::Foo; ... # foo accessor has 'foo' => ( is => 'ro', isa => 'Str', ); sub baz { my ($self, $c) = @_; # data from config $c->log->debug( $self->{foo} ); # logs 'bar' }

    Update: and as I git cloned to suggest updates, I see updates to that section of the POD are already in the pipeline!

    Update 2: The POD I should have read the whole time was Catalyst in the Cascading configuration section.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://922317]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2022-08-19 16:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found