[Catalyst-dev] PATCH for Catalyst::Plugin::ConfigLoader
John Napiorkowski
jjn1056 at yahoo.com
Wed Aug 22 16:36:21 GMT 2007
--- Jason Kohles <email at jasonkohles.com> wrote:
> On Aug 21, 2007, at 9:05 PM, Jonathan Rockway wrote:
>
> > Sorry to hijack this thread... but it reminded
> me... something I've
> > been
> > wanting for a while is:
> >
> > $c->config->{substitutions} = {
> > foo => sub { bar($_[0]) . baz($_[1]) }
> > ...
> > }
> >
> > Then in the config file:
> >
> > hello: __foo(Hello,World)__
> > ...
> >
> > Basically, let me specify my own macros in
> addition to (or overriding)
> > __HOME__ and __path_to()__. I'll write this, but
> if you want to do it
> > instead, all the better :)
> >
> I actually did something similar to this a while
> back, I keep meaning
> to clean it up and document and tests, but you know
> how it goes,
> never enough TUITs :)
>
> I took a slightly different approach though,
> abstracting out the
> function that is applied to values, so you can
> subclass it...
>
> sub finalize_config {
> my $c = shift;
> my $v = Data::Visitor::Callback->new(
> plain_value => sub {
> return unless defined $_;
> $c->config_substitutions( $_ );
> }
> );
> $v->visit( $c->config );
> }
>
> sub config_substitutions {
> my $c = shift;
> for ( @_ ) {
> s{__HOME__}{ $c->path_to( '' ) }e;
> s{__path_to\((.+)\)__}{ $c->path_to( split(
> '/', $1 ) ) }e;
> }
> }
>
>
> This way you can add a config_substitutions method
> to your app class
> for anything you want to add...
>
> package MyApp;
> sub config_substitutions {
> my $c = shift;
> $c->NEXT::config_substitutions( @_ );
> for ( @_ ) {
> s{__foo(.*?)__}{whatever};
> }
> }
I did something similar, also adding a generalized
method for creating local overrides, so that you could
merge in config changes via logged in username (for my
developers) and so forth. But I built it on top of
Config::Loader (which uses bits of Config::Any, but is
a little different) since it met my needs better.
Plus I made heavy use of Moose, so that's a
dependency. Don't know if we want to merge our stuff
or something.
--john
____________________________________________________________________________________
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
More information about the Catalyst-dev
mailing list