=== lib/Catalyst/View/TT.pm ================================================================== --- lib/Catalyst/View/TT.pm (revision 25850) +++ lib/Catalyst/View/TT.pm (local) @@ -119,6 +119,25 @@ if ( $c->debug && $config->{DUMP_CONFIG} ) { $c->log->debug( "TT Config: ", dump($config) ); } + + my $self = $class->NEXT::new( + $c, { %$config }, + ); + + # Set base include paths. Local'd in render if needed + $self->include_path($config->{INCLUDE_PATH}); + + $self->config($config); + + # Creation of template outside of call to new so that we can pass [ $self ] + # as INCLUDE_PATH config item, which then gets ->paths() called to get list + # of include paths to search for templates. + + # Use a weakend copy of self so we dont have loops preventing GC from working + my $copy = $self; + Scalar::Util::weaken($copy); + $config->{INCLUDE_PATH} = [ sub { $copy->paths } ]; + if ( $config->{PROVIDERS} ) { my @providers = (); if ( ref($config->{PROVIDERS}) eq 'ARRAY') { @@ -138,6 +157,14 @@ { $prov .= "::$pname"; } + # We copy the args people want from the config + # to the args + $p->{args} ||= {}; + if ($p->{copy_config}) { + map { $p->{args}->{$_} = $config->{$_} } + grep { exists $config->{$_} } + @{ $p->{copy_config} }; + } } eval "require $prov"; if(!$@) { @@ -154,25 +181,7 @@ $config->{LOAD_TEMPLATES} = \@providers; } } - - my $self = $class->NEXT::new( - $c, { %$config }, - ); - - # Set base include paths. Local'd in render if needed - $self->include_path($config->{INCLUDE_PATH}); - $self->config($config); - - # Creation of template outside of call to new so that we can pass [ $self ] - # as INCLUDE_PATH config item, which then gets ->paths() called to get list - # of include paths to search for templates. - - # Use a weakend copy of self so we dont have loops preventing GC from working - my $copy = $self; - Scalar::Util::weaken($copy); - $config->{INCLUDE_PATH} = [ sub { $copy->paths } ]; - $self->{template} = Template->new($config) || do { my $error = Template->error(); @@ -582,6 +591,20 @@ name => '+MyApp::Provider::Foo' +You can also specify the 'copy_config' key as an arrayref, to copy those keys +from the general config, into the config for the provider: + + DEFAULT_ENCODING => 'utf-8', + PROVIDERS => [ + { + name => 'Encoding', + copy_config => [qw(DEFAULT_ENCODING INCLUDE_PATH)] + } + ] + +This can prove useful when you want to use the additional_template_paths hack +in your own provider, or if you need to use Template::Provider::Encoding + =head2 HELPERS The L and === t/09providers.t ================================================================== --- t/09providers.t (revision 25850) +++ t/09providers.t (local) @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 3; +use Test::More tests => 5; use FindBin; use lib "$FindBin::Bin/lib"; @@ -9,4 +9,8 @@ my $response; ok(($response = request("/test_includepath?view=Providerconfig&template=test.tt"))->is_success, 'provider request'); -cmp_ok($response->content, 'eq', 'Faux-tastic!', 'provider worked'); \ No newline at end of file +cmp_ok($response->content, 'eq', 'Faux-tastic!', 'provider worked'); + + +ok(($response = request("/test_includepath?view=Providerconfig&template=testpath.tt&additionalpath=test_include_path"))->is_success, 'provider request'); +cmp_ok($response->content, 'eq', 'Faux-tastic!', 'provider worked'); === t/lib/TestApp/View/TT/Encoding.pm ================================================================== --- t/lib/TestApp/View/TT/Encoding.pm (revision 25850) +++ t/lib/TestApp/View/TT/Encoding.pm (local) @@ -0,0 +1,20 @@ +package TestApp::View::TT::Encoding; + +use strict; +use base 'Catalyst::View::TT'; + +__PACKAGE__->config( + PRE_CHOMP => 1, + POST_CHOMP => 1, + TEMPLATE_EXTENSION => '.tt', + 'TEMPLATE_EXTENSION' => '.tt', + 'DEFAULT_ENCODING' => 'utf-8', + PROVIDERS => [ + { + name => 'Encoding', + copy_config => [qw(INCLUDE_PATH DEFAULT_ENCODING PRE_CHOMP POST_CHOMP)] + } + ], +); + +1; === t/10providers.encoding.t ================================================================== --- t/10providers.encoding.t (revision 25850) +++ t/10providers.encoding.t (local) @@ -0,0 +1,20 @@ +use strict; +use warnings; +use Test::More; + +eval "use Template::Provider::Encoding"; +if ($@) { + plan skip_all => 'Template::Provider::Encoding'; +} else { + plan tests => 3; +} + +use FindBin; +use lib "$FindBin::Bin/lib"; + +use_ok('Catalyst::Test', 'TestApp'); + +my $response; +ok(($response = request("/test_includepath?view=Encoding&template=test.tt&additionalpath=test_include_path"))->is_success, 'provider request'); +cmp_ok($response->content, 'eq', 'hi', 'provider worked'); +