Mercurial > pub > Impl
comparison Lib/IMPL/Web/Application/ControllerUnit.pm @ 172:068acfe903c3
corrected schema resolution mechanism
author | sourcer |
---|---|
date | Mon, 20 Jun 2011 23:42:44 +0400 |
parents | 59e5fcb59d86 |
children | aaab45153411 |
comparison
equal
deleted
inserted
replaced
171:59e5fcb59d86 | 172:068acfe903c3 |
---|---|
55 warn "Bad transaction $method description"; | 55 warn "Bad transaction $method description"; |
56 $info = {}; | 56 $info = {}; |
57 } | 57 } |
58 | 58 |
59 $info->{wrapper} = 'TransactionWrapper'; | 59 $info->{wrapper} = 'TransactionWrapper'; |
60 $info->{method} ||= $method; | |
60 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; | 61 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; |
61 } | 62 } |
62 } | 63 } |
63 | 64 |
64 sub forms { | 65 sub forms { |
67 while ( my ($method,$info) = each %forms ) { | 68 while ( my ($method,$info) = each %forms ) { |
68 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method); | 69 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method); |
69 if ( not ref $info ) { | 70 if ( not ref $info ) { |
70 $self->class_data(CONTROLLER_METHODS)->{$method} = { | 71 $self->class_data(CONTROLLER_METHODS)->{$method} = { |
71 wrapper => 'FormWrapper', | 72 wrapper => 'FormWrapper', |
72 schema => $info | 73 schema => $info, |
74 method => $method | |
73 }; | 75 }; |
74 } elsif (ref $info eq 'HASH') { | 76 } elsif (ref $info eq 'HASH') { |
75 $info->{wrapper} = 'FormWrapper'; | 77 $info->{wrapper} = 'FormWrapper'; |
78 $info->{method} ||= $method; | |
76 | 79 |
77 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; | 80 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; |
78 } else { | 81 } else { |
79 die new IMPL::Exception("Unsupported method information",$self,$method); | 82 die new IMPL::Exception("Unsupported method information",$self,$method); |
80 } | 83 } |
127 | 130 |
128 sub TransactionWrapper { | 131 sub TransactionWrapper { |
129 my ($self,$method,$action,$methodInfo) = @_; | 132 my ($self,$method,$action,$methodInfo) = @_; |
130 | 133 |
131 my $unit = $self->new($action); | 134 my $unit = $self->new($action); |
132 return $unit->$method($unit->MakeParams($methodInfo)); | 135 my $handler = $methodInfo->{method}; |
136 return $unit->$handler($unit->MakeParams($methodInfo)); | |
133 } | 137 } |
134 | 138 |
135 sub FormWrapper { | 139 sub FormWrapper { |
136 my ($self,$method,$action,$methodInfo) = @_; | 140 my ($self,$method,$action,$methodInfo) = @_; |
137 | 141 |
147 my $transform = IMPL::DOM::Transform::PostToDOM->new( | 151 my $transform = IMPL::DOM::Transform::PostToDOM->new( |
148 undef, | 152 undef, |
149 $schema, | 153 $schema, |
150 $form | 154 $form |
151 ); | 155 ); |
156 | |
157 my $handler = $methodInfo->{method}; | |
152 | 158 |
153 $result{formName} = $form; | 159 $result{formName} = $form; |
154 $result{formSchema} = $schema; | 160 $result{formSchema} = $schema; |
155 | 161 |
156 if ($process) { | 162 if ($process) { |
161 } else { | 167 } else { |
162 $result{state} = STATE_CORRECT; | 168 $result{state} = STATE_CORRECT; |
163 my $unit = $self->new($action,\%result); | 169 my $unit = $self->new($action,\%result); |
164 | 170 |
165 eval { | 171 eval { |
166 $result{result} = $unit->$method($unit->MakeParams($methodInfo)); | 172 $result{result} = $unit->$handler($unit->MakeParams($methodInfo)); |
167 }; | 173 }; |
168 if (my $err = $@) { | 174 if (my $err = $@) { |
169 $result{state} = STATE_INVALID; | 175 $result{state} = STATE_INVALID; |
170 if (eval { $err->isa(typeof IMPL::WrongDataException) } ) { | 176 if (eval { $err->isa(typeof IMPL::WrongDataException) } ) { |
171 $result{formErrors} = $err->Args; | 177 $result{formErrors} = $err->Args; |
180 $result{formData} = $transform->Transform( $unit->$initMethod($unit->MakeParams($methodInfo)) ); | 186 $result{formData} = $transform->Transform( $unit->$initMethod($unit->MakeParams($methodInfo)) ); |
181 } else { | 187 } else { |
182 $result{formData} = $transform->Transform($action->query); | 188 $result{formData} = $transform->Transform($action->query); |
183 } | 189 } |
184 | 190 |
185 $result{formErrors} = $transform->Errors->as_list; | 191 # ignore errors for new forms |
192 #$result{formErrors} = $transform->Errors->as_list; | |
186 $result{state} = STATE_NEW; | 193 $result{state} = STATE_NEW; |
187 } | 194 } |
188 | 195 |
189 return \%result; | 196 return \%result; |
190 } | 197 } |