r11835@t0mlaptop (orig r11800): t0m | 2009-11-12 00:32:30 +0000
[catagits/Catalyst-View-TT.git] / lib / Catalyst / View / TT.pm
index 2d19a47..1b561e2 100644 (file)
@@ -9,7 +9,7 @@ use Template;
 use Template::Timer;
 use MRO::Compat;
 
-our $VERSION = '0.30';
+our $VERSION = '0.32';
 
 __PACKAGE__->mk_accessors('template');
 __PACKAGE__->mk_accessors('include_path');
@@ -207,10 +207,9 @@ sub process {
         return 0;
     }
 
-    my $output = $self->render($c, $template);
-
-    if (UNIVERSAL::isa($output, 'Template::Exception')) {
-        my $error = qq/Couldn't render template "$output"/;
+    my $output = eval { $self->render($c, $template) };
+    if (my $err = $@) {
+        my $error = qq/Couldn't render template "$template"/;
         $c->log->error($error);
         $c->error($error);
         return 0;
@@ -240,11 +239,9 @@ sub render {
         [ @{ $vars->{additional_template_paths} }, @{ $self->{include_path} } ]
         if ref $vars->{additional_template_paths};
 
-    unless ($self->template->process( $template, $vars, \$output ) ) {
-        return $self->template->error;
-    } else {
-        return $output;
-    }
+    $self->template->process( $template, $vars, \$output )
+        or die $self->template->error;
+    return $output;
 }
 
 sub template_vars {
@@ -289,7 +286,7 @@ something like this:
 
     use base 'Catalyst::View::TT';
 
-    __PACKAGE__->config->{DEBUG} = 'all';
+    __PACKAGE__->config(DEBUG => 'all');
 
 Now you can modify your action handlers in the main application and/or
 controllers to forward to your view class.  You might choose to do this
@@ -303,6 +300,38 @@ to the TT view class.
         $c->forward( $c->view('TT') );
     }
 
+But if you are using the standard auto-generated end action, you don't even need
+to do this!
+
+    # in MyApp::Controller::Root
+    sub end : ActionClass('RenderView') {} # no need to change this line
+
+    # in MyApp.pm
+    __PACKAGE__->config(
+        ...
+        default_view => 'TT',
+    );
+
+This will Just Work.  And it has the advantages that:
+
+=over 4
+
+=item *
+
+If you want to use a different view for a given request, just set 
+<< $c->stash->{current_view} >>.  (See L<Catalyst>'s C<< $c->view >> method
+for details.
+
+=item *
+
+<< $c->res->redirect >> is handled by default.  If you just forward to 
+C<View::TT> in your C<end> routine, you could break this by sending additional
+content.
+
+=back
+
+See L<Catalyst::Action::RenderView> for more details.
+
 =head2 CONFIGURATION
 
 There are a three different ways to configure your view class.  The
@@ -493,7 +522,7 @@ N.B. This is usually done automatically by L<Catalyst::Action::RenderView>.
 
 =head2 render($c, $template, \%args)
 
-Renders the given template and returns output, or a L<Template::Exception>
+Renders the given template and returns output. Throws a L<Template::Exception>
 object upon error.
 
 The template variables are set to C<%$args> if $args is a hashref, or
@@ -508,7 +537,7 @@ C<$template> can be anything that Template::process understands how to
 process, including the name of a template file or a reference to a test string.
 See L<Template::process|Template/process> for a full list of supported formats.
 
-To use the render method outside of your Catalyst app, just pass a undef context. 
+To use the render method outside of your Catalyst app, just pass a undef context.
 This can be useful for tests, for instance.
 
 It is possible to forward to the render method of a TT view from inside Catalyst