diff Lib/IMPL/Web/Application/ControllerUnit.pm @ 112:0ed8e2541b1c

Form processing mechanism
author wizard
date Tue, 18 May 2010 17:59:31 +0400
parents 6c25ea91c985
children 7b14e0122b79
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm	Tue May 18 01:33:37 2010 +0400
+++ b/Lib/IMPL/Web/Application/ControllerUnit.pm	Tue May 18 17:59:31 2010 +0400
@@ -1,8 +1,17 @@
 package IMPL::Web::Application::ControllerUnit;
-
+use strict;
 use base qw(IMPL::Object);
 
 use IMPL::Class::Property;
+use IMPL::DOM::Transform::PostToDOM;
+use IMPL::DOM::Schema;
+
+use constant {
+	CONTROLLER_METHODS => 'controller_methods',
+	STATE_CORRECT => 'correct',
+	STATE_NEW => 'new',
+	STATE_INVALID => 'invalid'
+};
 
 BEGIN {
 	public property action => prop_get | owner_set;
@@ -14,24 +23,77 @@
 }
 
 sub CTOR {
-	my ($this,$action) = @_;
+	my ($this,$action,$args) = @_;
 	
 	$this->action($action);
 	$this->application($action->application);
 	$this->query($action->query);
+	
+	$this->$_($args->{$_}) foreach qw(formData formSchema formErrors);
+}
+
+sub forms {
+	my ($self,%forms) = @_;
+	
+	while ( my ($method,$info) = each %forms ) {
+		die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method);
+		if ( not ref $info ) {
+			$self->class_data(CONTROLLER_METHODS)->{$method} = {
+				wrapper => 'FormWrapper',
+				schema => $info
+			};
+		} elsif (ref $info eq 'HASH') {
+			die new IMPL::Exception("A schema must be specified",$self,$method) unless $info->{schema};
+			
+			$self->class_data(CONTROLLER_METHODS)->{$method} = {
+				wrapper => 'FormWrapper',
+				schema => $info->{schema} 
+			};
+		} else {
+			die new IMPL::Exception("Unsupported method information",$self,$method);
+		}
+	}
+}
+
+sub transactions {
+	
 }
 
 sub InvokeAction {
 	my ($self,$method,$action) = @_;
 	
-	if ($self->can($method)) {
-		my $unit = $self->new($action);
-		$unit->$method();
+	if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) {
+		if (my $wrapper = $methodInfo->{wrapper}) {
+			return $self->$wrapper($method,$action,$methodInfo);
+		} else {
+			return $self->TransactionWrapper($method,$action,$methodInfo);			
+		}
 	} else {
 		die new IMPL::InvalidOperationException("Invalid method call",$self,$method);
 	}
 }
 
+sub TransactionWrapper {
+	my ($self,$method,$action,$methodInfo) = @_;
+	
+	my $unit = $self->new($action);
+	return $unit->$method();
+}
+
+sub FormWrapper {
+	my ($this,$method,$action,$methodInfo) = @_;
+	
+	my $schema = $this->loadSchema($methodInfo->{schema});
+	
+	my $process = $this->query->param('process') || 0;
+	
+	
+	
+	my %result = (
+		
+	);
+}
+
 1;
 
 __END__
@@ -142,7 +204,17 @@
 =item C<InvokeAction($method,$action)>
 
 Конструирует контекст выполнения транзакции, может быть переопределен для конструирования контекста по
-своимправилам. 
+своим правилам.
+
+=item C<TransactionWrapper($method,$action,$methodInfo)>
+
+Обертка для конструирования простых транзакций, может быть переопределен для конструирования контекста по
+своим правилам.
+
+=item C<FormWrapper($method,$action,$methodInfo)>
+
+Обертка для конструирования форм, может быть переопределен для конструирования контекста по
+своим правилам.
 
 =back