From 49b0368ba6c1d3d0bd1418a5914bc5265a22941f Mon Sep 17 00:00:00 2001
From: Simon Cozens <simon@simon-cozens.org>
Date: Tue, 6 Apr 2004 10:38:45 +0000
Subject: [PATCH] Add constants; refactor View classes and tests to use them;
 refactor out handler_guts to allow subcomponent stuff.

git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@116 48953598-375a-da11-a14b-00016c27c3ee
---
 lib/Maypole/View/Base.pm  | 20 +++++---------------
 lib/Maypole/View/Mason.pm |  3 ++-
 lib/Maypole/View/TT.pm    |  5 +++--
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/lib/Maypole/View/Base.pm b/lib/Maypole/View/Base.pm
index eaff544..37ca431 100644
--- a/lib/Maypole/View/Base.pm
+++ b/lib/Maypole/View/Base.pm
@@ -2,6 +2,7 @@ package Maypole::View::Base;
 use File::Spec;
 use UNIVERSAL::moniker;
 use strict;
+use Maypole::Constants;
 
 sub new { bless {}, shift } # By default, do nothing.
 
@@ -53,24 +54,12 @@ sub vars {
     %args;
 }
 
-sub do_it {
-    my ($self, $r) = @_;
-    my $template = Template->new({ INCLUDE_PATH => [ $self->paths($r) ]});
-    my $output;
-    if ($template->process($r->template, { $self->args($r) }, \$output)) {
-        $r->{output} = $output;
-        return 1;
-    } else { 
-         $r->{error} = $template->error;
-    }
-
-}
-
 sub process {
     my ($self, $r) = @_;
-    $self->template($r) || return $self->error($r);
+    my $status = $self->template($r);
+    return $self->error($r) if $status != OK;
     $r->{content_type} ||= "text/html";
-    return 200;
+    return OK;
 }
 
 sub error {
@@ -80,6 +69,7 @@ sub error {
     $r->{content_type} = "text/plain";
     $r->{output} = $r->{error};
     $r->send_output;
+    return ERROR;
 }
 
 sub template { die shift()." didn't define a decent template method!" }
diff --git a/lib/Maypole/View/Mason.pm b/lib/Maypole/View/Mason.pm
index 4d50bbd..90b3b4e 100644
--- a/lib/Maypole/View/Mason.pm
+++ b/lib/Maypole/View/Mason.pm
@@ -1,6 +1,7 @@
 package Maypole::View::Mason;
 use base 'Maypole::View::Base';
 use HTML::Mason;
+use Maypole::Constants;
 
 sub template {
     my ($self, $r) = @_;
@@ -13,7 +14,7 @@ sub template {
     );
     $mason->exec($r->template, $self->vars($r))
     $r->{output} = $output;
-    return 1;
+    return OK;
 }
 
 1;
diff --git a/lib/Maypole/View/TT.pm b/lib/Maypole/View/TT.pm
index 15581e8..0e8d89f 100644
--- a/lib/Maypole/View/TT.pm
+++ b/lib/Maypole/View/TT.pm
@@ -1,5 +1,6 @@
 package Maypole::View::TT;
 use base 'Maypole::View::Base';
+use Maypole::Constants;
 use Template;
 
 sub template {
@@ -8,10 +9,10 @@ sub template {
     my $output;
     if ($template->process($r->template, { $self->vars($r) }, \$output)) {
         $r->{output} = $output;
-        return 1;
+        return OK;
     } else {
         $r->{error} = $template->error;
-        return 0;
+        return ERROR;
     }
 }
 
-- 
2.39.5