]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Maypole/View/TT.pm
made setting user() and session() backward compatible
[maypole.git] / lib / Maypole / View / TT.pm
index fb94767f0bf24964720fb516110395dd7936c2af..7d28440137df92a93821074f2082ddd0d4b6b4d4 100644 (file)
@@ -3,16 +3,22 @@ use base 'Maypole::View::Base';
 use Maypole::Constants;
 use Template;
 use File::Spec::Functions qw(catdir tmpdir);
 use Maypole::Constants;
 use Template;
 use File::Spec::Functions qw(catdir tmpdir);
+use Data::Dumper;
 
 
-our $error_template; 
+our $error_template;
 { local $/; $error_template = <DATA>; }
 
 { local $/; $error_template = <DATA>; }
 
+our $VERSION = '2.12';
+
 use strict;
 
 sub template {
   my ( $self, $r ) = @_;
   unless ($self->{tt}) {
     my $view_options = $r->config->view_options || {};
 use strict;
 
 sub template {
   my ( $self, $r ) = @_;
   unless ($self->{tt}) {
     my $view_options = $r->config->view_options || {};
+    if ($r->debug) {
+      $view_options->{DEBUG} = 0;
+    }
     $self->{provider} = Template::Provider->new($view_options);
     $self->{tt}       = Template->new({
                                       %$view_options,
     $self->{provider} = Template::Provider->new($view_options);
     $self->{tt}       = Template->new({
                                       %$view_options,
@@ -34,11 +40,13 @@ sub template {
     return OK;
   } else {
     if ($@) {
     return OK;
   } else {
     if ($@) {
-      warn "fatal error in template '$template_file' : $@\n";
-      $r->{error} = "fatal error in template '$template_file' : $@";
+      my $error = "fatal error in template '$template_file' : $@\nTT paths : " . join(', ',$self->paths($r)) . "\n";
+      $r->warn($error);
+      $r->{error} = $error;
     } else {
     } else {
-      warn "TT error for template '$template_file'\n" . $self->{tt}->error;
-      $r->{error} = "TT error for template '$template_file'\n" . $self->{tt}->error;
+      my $error = "TT error for template '$template_file'\n" . $self->{tt}->error . "\nTT paths : " . join(', ',$self->paths($r)) . "\n";
+      $r->warn($error);
+      $r->{error} = $error;
     }
     return ERROR;
   }
     }
     return ERROR;
   }
@@ -49,8 +57,6 @@ sub report_error {
     my ($self, $r, $error, $type) = @_;
     my $output;
 
     my ($self, $r, $error, $type) = @_;
     my $output;
 
-    warn "self : $self, r : $r, error : $error, type : $type\n";
-
     # Need to be very careful here.
     my $tt = Template->new;
     unless (ref $r->{config}) {
     # Need to be very careful here.
     my $tt = Template->new;
     unless (ref $r->{config}) {
@@ -58,11 +64,14 @@ sub report_error {
       $error .= '<br> There was a problem finding configuration for this request';
       $r->{config} ||= {};
     }
       $error .= '<br> There was a problem finding configuration for this request';
       $r->{config} ||= {};
     }
+
+    $r->warn("report_error - reporting error to user : $error\n");
+
     if ($tt->process(\$error_template,
                     { err_type => $type, error => $error,
                       config => $r->{config},
                       request => $r,
     if ($tt->process(\$error_template,
                     { err_type => $type, error => $error,
                       config => $r->{config},
                       request => $r,
-                      paths => $self->paths($r),
+                      paths => [ $self->paths($r) ],
                       eval{$self->vars($r)} }, \$output )) {
         $r->{output} = $output;
         if ($tt->error) { $r->{output} = "<html><body>Even the error template
                       eval{$self->vars($r)} }, \$output )) {
         $r->{output} = $output;
         if ($tt->error) { $r->{output} = "<html><body>Even the error template
@@ -286,6 +295,18 @@ truncate, format, escape or encode trivially. A useful selection is included
 with Template Toolkit and they can also be found on CPAN or can be written
 easily. See L<Template::Manual::Filters>.
 
 with Template Toolkit and they can also be found on CPAN or can be written
 easily. See L<Template::Manual::Filters>.
 
+TT provides stderr and stdout filters, which allow you to write handy macros
+like this one to output debug information to your web server log, etc :
+
+=over 4
+
+[% MACRO debug_msg(text)
+    FILTER stderr; "[TT debug_msg] $text\n"; END;
+%]
+
+=back
+
+
 TT Macros allow you to reuse small blocks of content, directives, etc. The MACRO
 directive allows you to define a directive or directive block which is then
 evaluated each time the macro is called. Macros can be passed named parameters
 TT Macros allow you to reuse small blocks of content, directives, etc. The MACRO
 directive allows you to define a directive or directive block which is then
 evaluated each time the macro is called. Macros can be passed named parameters
@@ -408,6 +429,11 @@ the path "[% request.path %]". The error text returned was:
     <tr> <td class="lhs" width="35%"> <b>[% attribute %]</b> </td> <td class="rhs" width="65%"> [%
     request.$attribute.list.join(" , ") %] </td></tr>
     [% END %]
     <tr> <td class="lhs" width="35%"> <b>[% attribute %]</b> </td> <td class="rhs" width="65%"> [%
     request.$attribute.list.join(" , ") %] </td></tr>
     [% END %]
+    <tr><td colspan="2"></tr>
+    <tr><td class="lhs" colspan="2"><b>CGI Parameters</b> </td></tr>
+    [% FOREACH param IN request.params %]
+    <tr> <td class="lhs" width="35%">[% param.key %]</td> <td class="rhs" width="65%"> [% param.value %] </td></tr>
+    [% END %]
 </table>
 
 <h2> Website / Template Paths </h2>
 </table>
 
 <h2> Website / Template Paths </h2>