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-> = {
> 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{ $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(.*?)__};
}
}
--
Jason Kohles
email jasonkohles.com
http://www.jasonkohles.co
m/
"A witty saying proves nothing." -- Voltaire
_______________________________________________
Catalyst-dev mailing list
Catalyst-dev lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst-dev
|