Update of /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest/Recorder
In directory sc8-pr-cvs1:/tmp/cvs-serv17274/lib/HTTP/WebTest/Recorder
Modified Files:
Controller.pm Action.pm
Log Message:
Simplify design of actions by merging all action classes in single
action package with procedural style subs
Index: Controller.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest/Recorder/Controller.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Controller.pm 25 Jan 2003 14:54:52 -0000 1.1
--- Controller.pm 1 Feb 2003 22:25:33 -0000 1.2
***************
*** 12,15 ****
--- 12,16 ----
use HTTP::WebTest::Recorder::Exceptions;
+ use HTTP::WebTest::Recorder::Action;
# constructor
***************
*** 33,41 ****
use vars qw(%DISPATCH);
! %DISPATCH = (list => 'HTTP::WebTest::Recorder::Action::List',
! request => 'HTTP::WebTest::Recorder::Action::Request',
! wtscript => 'HTTP::WebTest::Recorder::Action::WTScript',
! enable => 'HTTP::WebTest::Recorder::Action::Enable',
! default => 'HTTP::WebTest::Recorder::Action');
# serves requests for web interface of the proxy
--- 34,42 ----
use vars qw(%DISPATCH);
! %DISPATCH = (list => \&HTTP::WebTest::Recorder::Action::list_action,
! request => \&HTTP::WebTest::Recorder::Action::request_action,
! wtscript => \&HTTP::WebTest::Recorder::Action::wtscript_action,
! enable => \&HTTP::WebTest::Recorder::Action::enable_action,
! default => \&HTTP::WebTest::Recorder::Action::default_action);
# serves requests for web interface of the proxy
***************
*** 50,60 ****
$self->view($param{action});
! my $action_package = $DISPATCH{$param{action}} || $DISPATCH{default};
! eval "require $action_package";
! my $action = $action_package->new;
my $response;
eval {
! $response = $self->process_template($action->execute($self));
};
if($@) {
--- 51,59 ----
$self->view($param{action});
! my $action = $DISPATCH{$param{action}} || $DISPATCH{default};
my $response;
eval {
! $response = $self->process_template($action->($self));
};
if($@) {
Index: Action.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest-Recorder/lib/HTTP/WebTest/Recorder/Action.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Action.pm 25 Jan 2003 14:54:52 -0000 1.1
--- Action.pm 1 Feb 2003 22:25:33 -0000 1.2
***************
*** 1,22 ****
package HTTP::WebTest::Recorder::Action;
- # $Id$
-
use strict;
! # constructor
! sub new {
! my $class = shift;
! my $self = bless {}, $class;
! return $self;
}
! # serves requests
! sub execute {
! my $self = shift;
my $controller = shift;
! return(action => $self,
! controller => $controller);
}
--- 1,55 ----
package HTTP::WebTest::Recorder::Action;
use strict;
! use HTTP::WebTest::Parser;
!
! sub default_action {
! my $controller = shift;
!
! return(controller => $controller);
}
! sub enable_action {
my $controller = shift;
! my $enable = $controller->cgi->param('enable');
! $controller->recorder->is_recording($enable);
!
! $controller->redirect('list');
! }
!
! sub list_action {
! my $controller = shift;
!
! return(default_action($controller),
! tests => $controller->recorder->tests);
! }
!
! sub request_action {
! my $controller = shift;
!
! my $num = $controller->cgi->param('num');
! my $test = $controller->recorder->tests->[$num];
!
! return(default_action($controller),
! test => $test);
! }
! sub wtscript_action {
! my $controller = shift;
!
! my $wtscript = (join "\n", map _test2wtscript($_),
! @{$controller->recorder->tests});
!
! return(default_action($controller),
! wtscript => $wtscript);
! }
!
! sub _test2wtscript {
! my $test = shift;
!
! my @params = map +($_ => $test->params->{$_}), sort keys %{$test->params};
!
! return HTTP::WebTest::Parser->write_test(\@params);
}
|