[Catalyst-commits] r7425 - in trunk/Catalyst-View-TT: . lib/Catalyst/View t t/lib/TestApp t/lib/TestApp/View/TT

gphat at dev.catalyst.perl.org gphat at dev.catalyst.perl.org
Wed Jan 30 21:02:49 GMT 2008


Author: gphat
Date: 2008-01-30 21:02:48 +0000 (Wed, 30 Jan 2008)
New Revision: 7425

Added:
   trunk/Catalyst-View-TT/t/09providers.t
   trunk/Catalyst-View-TT/t/lib/TestApp/FauxProvider.pm
   trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Providerconfig.pm
Modified:
   trunk/Catalyst-View-TT/Changes
   trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm
Log:
Add fully-qualified provider classname support to View::TT


Modified: trunk/Catalyst-View-TT/Changes
===================================================================
--- trunk/Catalyst-View-TT/Changes	2008-01-29 23:07:40 UTC (rev 7424)
+++ trunk/Catalyst-View-TT/Changes	2008-01-30 21:02:48 UTC (rev 7425)
@@ -1,5 +1,9 @@
 Revision history for Perl extension Catalyst::View::TT.
 
+0.27
+	   - Document providers and support unary plus for fully qualified class
+		 names
+
 0.26   2008-01-11 20:12:00
        - Fix pod coverage
        - Change from =item to =head2

Modified: trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm
===================================================================
--- trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm	2008-01-29 23:07:40 UTC (rev 7424)
+++ trunk/Catalyst-View-TT/lib/Catalyst/View/TT.pm	2008-01-30 21:02:48 UTC (rev 7425)
@@ -131,7 +131,13 @@
                 }
                 else
                 {
-                    $prov .="::$pname" if($pname ne '_file_');
+                    if($pname =~ s/^\+//) {
+                        $prov = $pname;
+                    }
+                    else
+                    {
+                        $prov .= "::$pname";
+                    }
                 }
                 eval "require $prov";
                 if(!$@) {
@@ -545,6 +551,37 @@
 Would by default look for a template in <root>/test/test. If you set TEMPLATE_EXTENSION to '.tt', it will look for
 <root>/test/test.tt.
 
+=head2 C<PROVIDERS>
+
+Allows you to specify the template providers that TT will use.
+
+    MyApp->config({
+        name     => 'MyApp',
+        root     => MyApp->path_to('root'),
+        'V::TT' => {
+            PROVIDERS => [
+                {
+                    name    => 'DBI',
+                    args    => {
+                        DBI_DSN => 'dbi:DB2:books',
+                        DBI_USER=> 'foo'
+                    }
+                }, {
+                    name    => '_file_',
+                    args    => {}
+                }
+            ]
+        },
+    });
+
+The 'name' key should correspond to the class name of the provider you
+want to use.  The _file_ name is a special case that represents the default
+TT file-based provider.  By default the name is will be prefixed with
+'Template::Provider::'.  You can fully qualify the name by using a unary
+plus:
+
+    name => '+MyApp::Provider::Foo'
+
 =head2 HELPERS
 
 The L<Catalyst::Helper::View::TT> and

Added: trunk/Catalyst-View-TT/t/09providers.t
===================================================================
--- trunk/Catalyst-View-TT/t/09providers.t	                        (rev 0)
+++ trunk/Catalyst-View-TT/t/09providers.t	2008-01-30 21:02:48 UTC (rev 7425)
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+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

Added: trunk/Catalyst-View-TT/t/lib/TestApp/FauxProvider.pm
===================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/FauxProvider.pm	                        (rev 0)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/FauxProvider.pm	2008-01-30 21:02:48 UTC (rev 7425)
@@ -0,0 +1,23 @@
+package TestApp::FauxProvider;
+
+use Template::Constants;
+
+use base qw(Template::Provider);
+
+sub fetch {
+    my $self = shift();
+    my $name = shift();
+    
+    my $data = {
+        name    => $name,
+        path    => $name,
+        text    => 'Faux-tastic!',
+        'time'  => time(),
+        load    => time()
+    };
+
+    my ($page, $error) = $self->_compile($data);
+    return ($page->{'data'}, $error);
+}
+
+1;
\ No newline at end of file

Added: trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Providerconfig.pm
===================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Providerconfig.pm	                        (rev 0)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Providerconfig.pm	2008-01-30 21:02:48 UTC (rev 7425)
@@ -0,0 +1,22 @@
+package TestApp::View::TT::Providerconfig;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+__PACKAGE__->config(
+    PRE_CHOMP          => 1,
+    POST_CHOMP         => 1,
+    TEMPLATE_EXTENSION => '.tt',
+    PROVIDERS           => [
+        {
+            name    => '+TestApp::FauxProvider',
+            args    => {}
+        },
+        # {
+        #     name    => '_file_',
+        #     args    => {}
+        # }
+    ]
+);
+
+1;




More information about the Catalyst-commits mailing list