Re: [Catalyst] Merging configs
On Thu, Mar 08, 2007 at 05:25:55PM -0500, Christopher H. Laco wrote: Catalyst config support a 'local' config file in addition to the regular one. I'm not sure on the exact file name, but I think it's myapp_local.yml That's also a shallow merge, IIRC. It just calls $c-config with the local config. I ended up with something like this -- at this time I only want to be able to merge in my data represented as hashes. sub deep_merge { my ( $self, $config, $new_hash ) = @_; for my $key ( keys %$new_hash ) { my $value = $new_hash-{$key}; if ( ref $value eq 'HASH' ) { $config-{$key} ||= {}; $self-deep_merge( $config-{$key}, $value ); } else { $config-{$key} = $value; } } } -- Bill Moseley [EMAIL PROTECTED] ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Merging configs
Bill Moseley wrote: On Thu, Mar 08, 2007 at 05:25:55PM -0500, Christopher H. Laco wrote: Catalyst config support a 'local' config file in addition to the regular one. I'm not sure on the exact file name, but I think it's myapp_local.yml That's also a shallow merge, IIRC. It just calls $c-config with the local config. The merge is a little more complicated than you think. It uses Catalyst::Utils::merge_hashes underneath http://dev.catalystframework.org/browser/trunk/Catalyst-Runtime/lib/Catalyst/Utils.pm#L263 for reference, the config() routine: http://dev.catalystframework.org/browser/trunk/Catalyst-Runtime/lib/Catalyst/Component.pm#L88 -Brian ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Merging configs
On Fri, Mar 09, 2007 at 11:16:00AM -0400, Brian Cassidy wrote: http://dev.catalystframework.org/browser/trunk/Catalyst-Runtime/lib/Catalyst/Utils.pm#L263 for reference, the config() routine: http://dev.catalystframework.org/browser/trunk/Catalyst-Runtime/lib/Catalyst/Component.pm#L88 Oops, I looked at an old version of Component.pm that does (did) this: sub config { my $self = shift; $self-_config( {} ) unless $self-_config; if (@_) { my $config = @_ 1 ? [EMAIL PROTECTED] : $_[0]; while ( my ( $key, $val ) = each %$config ) { $self-_config-{$key} = $val; } } return $self-_config; } -- Bill Moseley [EMAIL PROTECTED] ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Merging configs
Bill Moseley wrote: My YAML file has sections that are specific to what server is running. That is, I have: # Default config foo: bar name: foo servers: staging: config: foo: baz ... devel: config: ... production: config: ... So in my setup() I do basically: $self-config( $self-config-{servers}{$server_mode}{config} ); Of course, that's a shallow hash merge. Now, my YAML config also configures my View::TT, for example: V::TT: WRAPPER: page/wrapper.tt PRE_PROCESS: config.tt TEMPLATE_EXTENSION: .tt PRE_CHOMP: 0 POST_CHOMP: 0 TIMER: 0 and I'd like to be able to do something like this: servers: devel: config: V::TT: DEBUG: provider BLA: 123 but that shallow merge above wipes out the initial V::TT settings. Is the answer Hash::Merge? Or does Catalyst have anything to help here? Catalyst config support a 'local' config file in addition to the regular one. I'm not sure on the exact file name, but I think it's myapp_local.yml -=Chris signature.asc Description: OpenPGP digital signature ___ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/