Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest
In directory sc8-pr-cvs1:/tmp/cvs-serv4361/lib/HTTP/WebTest
Modified Files:
Controller.pm Action.pm
Log Message:
Move responsibility of processing templates from action to controller;
Rename action's method template_data() to execute()
Index: Controller.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest/Controller.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Controller.pm 7 Jan 2003 21:07:22 -0000 1.2
--- Controller.pm 18 Jan 2003 18:51:13 -0000 1.3
***************
*** 7,10 ****
--- 7,11 ----
use CGI;
use File::Spec;
+ use HTTP::Status;
use HTTP::WebTest::Utils qw(make_access_method);
use Template;
***************
*** 44,51 ****
$self->view($param{action});
! my $dispatch = $DISPATCH{$param{action}} || $DISPATCH{default};
! eval "require $dispatch";
! $dispatch = $dispatch->new;
! return $dispatch->execute($self);
}
--- 45,78 ----
$self->view($param{action});
! my $action_package = $DISPATCH{$param{action}} || $DISPATCH{default};
! eval "require $action_package";
! my $action = $action_package->new;
!
! return $self->process_template($action->execute($self));
! }
!
! # populates template with data returned by action object and generates
! # response based on template output
! sub process_template {
! my $self = shift;
! my %data = @_;
!
! my $content = '';
! if($self->template->process($self->view, \%data, \$content)) {
! my $response = HTTP::Response->new(RC_OK);
! $response->header(Content_Type => 'text/html');
! $response->content($content);
! return $response;
! } elsif($self->template->error =~ /file error - .*: not found/) {
! my $response = HTTP::Response->new(RC_NOT_FOUND);
! $response->header(Content_Type => 'text/plain');
! $response->content('Not Found');
! return $response;
! } else {
! my $response = HTTP::Response->new(RC_INTERNAL_SERVER_ERROR);
! $response->header(Content_Type => 'text/plain');
! $response->content($self->template->error);
! return $response;
! }
}
Index: Action.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest/Action.pm,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Action.pm 3 Jan 2003 23:01:22 -0000 1.1.1.1
--- Action.pm 18 Jan 2003 18:51:13 -0000 1.2
***************
*** 5,10 ****
use strict;
- use HTTP::Status;
-
# constructor
sub new {
--- 5,8 ----
***************
*** 16,45 ****
# serves requests
sub execute {
- my $self = shift;
- my $controller = shift;
-
- my $content = '';
- my %data = $self->template_data($controller);
-
- if($controller->template->process($controller->view, \%data, \$content)) {
- my $response = HTTP::Response->new(RC_OK);
- $response->header(Content_Type => 'text/html');
- $response->content($content);
- return $response;
- } elsif($controller->template->error =~ /file error - .*: not found/) {
- my $response = HTTP::Response->new(RC_NOT_FOUND);
- $response->header(Content_Type => 'text/plain');
- $response->content('Not Found');
- return $response;
- } else {
- my $response = HTTP::Response->new(RC_INTERNAL_SERVER_ERROR);
- $response->header(Content_Type => 'text/plain');
- $response->content($controller->template->error);
- return $response;
- }
- }
-
- # returns data to fill in template
- sub template_data {
my $self = shift;
my $controller = shift;
--- 14,17 ----
|