[Catalyst] __PACKAGE__->config for components from YAML
Matt S Trout
dbix-class at trout.me.uk
Sat Jan 14 05:40:17 CET 2006
On Fri, Jan 13, 2006 at 07:07:05PM -0800, apv wrote:
> So, in a "site.yml" config file I'm doing this:
>
> Model::DB:
> password: ~
> user: ~
> server: blahblah
> port: ~
>
> And then from MyApp::Model::DB I want to do this:
>
> my $SERVER = __PACKAGE__->config->{server} || 'localhost';
>
> But it doesn't work. Should it? What am I doing wrong?
No, I wouldn't expect that to work. You'll need to interrupt during ->new()
when the component is instantiated with the app instance config. Something
like
sub new {
my $class = shift;
my $new = $class->NEXT::new(@_);
$new->{server} ||= 'localhost';
return $new;
}
should do the trick (c.f. Model::DBIC instantiating its Loader object during
new)
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list