lib/Catalyst/View/TT.pm
Makefile.PL
MANIFEST This list of files
-META.yml Module meta-data (added by MakeMaker)
+META.yml
README
t/01use.t
t/02pod.t
t/06includepath.t
t/07render.t
t/08cycle.t
+t/09providers.t
+t/10providers.encoding.t
t/lib/TestApp.pm
+t/lib/TestApp/FauxProvider.pm
t/lib/TestApp/root/specified_template.tt
t/lib/TestApp/root/test.tt
t/lib/TestApp/root/test_include_path/testpath.tt
t/lib/TestApp/View/TT/Appconfig.pm
+t/lib/TestApp/View/TT/Encoding.pm
t/lib/TestApp/View/TT/Includepath.pm
t/lib/TestApp/View/TT/Includepath2.pm
t/lib/TestApp/View/TT/Includepath3.pm
t/lib/TestApp/View/TT/Pkgconfig.pm
+t/lib/TestApp/View/TT/Providerconfig.pm
# use the helper to create your View
myapp_create.pl view TT TT
-# configure in lib/MyApp.pm
+# configure in lib/MyApp.pm (Could be set from configfile instead)
MyApp->config(
name => 'MyApp',
MyApp->path_to( 'root', 'src' ),
MyApp->path_to( 'root', 'lib' ),
],
+ TEMPLATE_EXTENSION => '.tt',
+ CATALYST_VAR => 'c',
+ TIMER => 0,
+ # Not set by default
PRE_PROCESS => 'config/main',
WRAPPER => 'site/wrapper',
- TEMPLATE_EXTENSION => '.tt',
-
- # two optional config items
- CATALYST_VAR => 'Catalyst',
- TIMER => 1,
},
);
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') {
{
$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(!$@) {
$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 {
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<Catalyst::Helper::View::TT> and
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 5;
use FindBin;
use lib "$FindBin::Bin/lib";
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');