# HG changeset patch # User wizard # Date 1274191171 -14400 # Node ID 0ed8e2541b1c40c92a603f4aaa9ab398fa3032a9 # Parent 6c25ea91c985af9055354f02434d2dee74e8a7ea Form processing mechanism diff -r 6c25ea91c985 -r 0ed8e2541b1c Lib/IMPL/DOM/Navigator/Builder.pm --- a/Lib/IMPL/DOM/Navigator/Builder.pm Tue May 18 01:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Navigator/Builder.pm Tue May 18 17:59:31 2010 +0400 @@ -17,7 +17,7 @@ } our %CTOR = ( - 'IMPL::DOM::Navigator' => sub { IMPL::DOM::Document::Empty; } + 'IMPL::DOM::Navigator' => sub { IMPL::DOM::Document->Empty; } ); sub CTOR { @@ -108,6 +108,20 @@ $this->SUPER::Back(); } +sub saveState { + my ($this) = @_; + + $this->{$_schemaNavi}->saveState; + $this->SUPER::saveState; +} + +sub restoreState { + my ($this) = @_; + + $this->{$_schemaNavi}->restoreState; + $this->SUPER::restoreState; +} + 1; __END__ diff -r 6c25ea91c985 -r 0ed8e2541b1c Lib/IMPL/DOM/Transform/PostToDOM.pm --- a/Lib/IMPL/DOM/Transform/PostToDOM.pm Tue May 18 01:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm Tue May 18 17:59:31 2010 +0400 @@ -1,8 +1,8 @@ -package IMPL::DOM::PostToDOM; +package IMPL::DOM::Transform::PostToDOM; use strict; use warnings; -use IMPL::DOM::Navigator; +use IMPL::DOM::Navigator::Builder; use IMPL::Class::Property; use base qw(IMPL::Transform); @@ -21,43 +21,38 @@ sub CTOR { my ($this,$docClass,$docSchema) = @_; - $docClass ||= 'IMPL::DOM::Document' + $docClass ||= 'IMPL::DOM::Document'; + + $this->_navi( + IMPL::DOM::Navigator::Builder->new( + $docClass, + $docSchema + ) + ); } sub TransformPostData { my ($this,$data) = @_; - my $navi = $this->Navigator; + my $navi = $this->_navi; + + my % while (my ($key,$value) = each %$data) { # TODO: review + $navi->save; my $node = $navi->Navigate(split /\//, $key); $node->nodeValue($value); + $navi->resore; } return $navi->Document; } -package IMPL::DOM::PostToDOM::Navigator; -use base qw(IMPL::DOM::Navigator::Builder); - -__PACKAGE__->PassThroughArgs; +sub -sub Navigate { - my ($this,@path) = @_; - - if (@path > 1) { - my $node; - foreach my $query (@path) { - unless($this->dosafe(sub { - $node = $this->SUPER::Navigate($query); - })) { - $node = $this->NavigateCreate($query); - } - } - } else { - die new IMPL::InvalidArgumentException("A path is a required parameter"); - } +sub TransformErrors { + return $_[0]->_navi->BuildErrors; } 1; diff -r 6c25ea91c985 -r 0ed8e2541b1c Lib/IMPL/Web/Application/ControllerUnit.pm --- 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 Конструирует контекст выполнения транзакции, может быть переопределен для конструирования контекста по -своимправилам. +своим правилам. + +=item C + +Обертка для конструирования простых транзакций, может быть переопределен для конструирования контекста по +своим правилам. + +=item C + +Обертка для конструирования форм, может быть переопределен для конструирования контекста по +своим правилам. =back