[Catalyst-commits] r7649 - in trunk/Catalyst-View-TT: .
lib/Catalyst/Helper/View lib/Catalyst/View t t/lib/TestApp/View/TT
marcus at dev.catalyst.perl.org
marcus at dev.catalyst.perl.org
Wed Apr 30 11:28:18 BST 2008
Author: marcus
Date: 2008-04-30 11:28:17 +0100 (Wed, 30 Apr 2008)
New Revision: 7649
Added:
trunk/Catalyst-View-TT/t/10providers.encoding.t
trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Encoding.pm
Modified:
trunk/Catalyst-View-TT/Changes
trunk/Catalyst-View-TT/MANIFEST
trunk/Catalyst-View-TT/lib/Catalyst/Helper/View/TTSite.pm
trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm
trunk/Catalyst-View-TT/t/09providers.t
Log:
copy_config support
Modified: trunk/Catalyst-View-TT/Changes
===================================================================
--- trunk/Catalyst-View-TT/Changes 2008-04-30 10:06:29 UTC (rev 7648)
+++ trunk/Catalyst-View-TT/Changes 2008-04-30 10:28:17 UTC (rev 7649)
@@ -1,8 +1,9 @@
Revision history for Perl extension Catalyst::View::TT.
0.27
- - Document providers and support unary plus for fully qualified class
- names
+ - Add copy_config support to PROVIDERS
+ - Document providers and support unary plus for fully qualified class
+ names as in the example in TT pod.
0.26 2008-01-11 20:12:00
- Fix pod coverage
@@ -106,5 +107,4 @@
0.02 Tue Feb 01 02:00:00 2005
- using $c->req->match instead of $c->req->action
-0.01 Fri Jan 28 22:00:00 2005
- - first release
+0.01 Fri Jan 28 22:00:00 2
Modified: trunk/Catalyst-View-TT/MANIFEST
===================================================================
--- trunk/Catalyst-View-TT/MANIFEST 2008-04-30 10:06:29 UTC (rev 7648)
+++ trunk/Catalyst-View-TT/MANIFEST 2008-04-30 10:28:17 UTC (rev 7649)
@@ -15,7 +15,7 @@
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
@@ -25,12 +25,17 @@
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
Modified: trunk/Catalyst-View-TT/lib/Catalyst/Helper/View/TTSite.pm
===================================================================
--- trunk/Catalyst-View-TT/lib/Catalyst/Helper/View/TTSite.pm 2008-04-30 10:06:29 UTC (rev 7648)
+++ trunk/Catalyst-View-TT/lib/Catalyst/Helper/View/TTSite.pm 2008-04-30 10:28:17 UTC (rev 7649)
@@ -123,7 +123,6 @@
use base 'Catalyst::View::TT';
__PACKAGE__->config({
- CATALYST_VAR => 'Catalyst',
INCLUDE_PATH => [
[% app %]->path_to( 'root', 'src' ),
[% app %]->path_to( 'root', 'lib' )
Modified: trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm
===================================================================
--- trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm 2008-04-30 10:06:29 UTC (rev 7648)
+++ trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm 2008-04-30 10:28:17 UTC (rev 7649)
@@ -23,7 +23,7 @@
# 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',
@@ -34,13 +34,12 @@
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,
},
);
@@ -119,6 +118,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 +156,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 +180,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 +590,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<Catalyst::Helper::View::TT> and
Modified: trunk/Catalyst-View-TT/t/09providers.t
===================================================================
--- trunk/Catalyst-View-TT/t/09providers.t 2008-04-30 10:06:29 UTC (rev 7648)
+++ trunk/Catalyst-View-TT/t/09providers.t 2008-04-30 10:28:17 UTC (rev 7649)
@@ -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');
Added: trunk/Catalyst-View-TT/t/10providers.encoding.t
===================================================================
--- trunk/Catalyst-View-TT/t/10providers.encoding.t (rev 0)
+++ trunk/Catalyst-View-TT/t/10providers.encoding.t 2008-04-30 10:28:17 UTC (rev 7649)
@@ -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');
+
Added: trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Encoding.pm
===================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Encoding.pm (rev 0)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Encoding.pm 2008-04-30 10:28:17 UTC (rev 7649)
@@ -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;
More information about the Catalyst-commits
mailing list