annotate Lib/IMPL/Web/Application/ControllerUnit.pm @ 146:60fd224f3e3c

fixed cgi parameters processing Added parameters inflating feature Added preprocessed templates, reformatting output
author wizard
date Mon, 26 Jul 2010 03:19:06 +0400
parents b56ebc31bf18
children e6447ad85cb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
1 use strict;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
2 package IMPL::Web::Application::ControllerUnit;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
3 use base qw(IMPL::Object);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
4
c13a215508ca Refactoring,
wizard
parents:
diff changeset
5 use IMPL::Class::Property;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
6 use IMPL::DOM::Transform::PostToDOM;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
7 use IMPL::DOM::Schema;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
8 use Class::Inspector;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
9 use File::Spec;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
10 use Sub::Name;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
11
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
12 use constant {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
13 CONTROLLER_METHODS => 'controller_methods',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
14 STATE_CORRECT => 'correct',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
15 STATE_NEW => 'new',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
16 STATE_INVALID => 'invalid'
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
17 };
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
18
c13a215508ca Refactoring,
wizard
parents:
diff changeset
19 BEGIN {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
20 public property action => prop_get | owner_set;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
21 public property application => prop_get | owner_set;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
22 public property query => prop_get | owner_set;
144
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 142
diff changeset
23 public property response => prop_get | owner_set;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
24 public property formData => prop_get | owner_set;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
25 public property formSchema => prop_get | owner_set;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
26 public property formErrors => prop_get | owner_set;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
27 }
c13a215508ca Refactoring,
wizard
parents:
diff changeset
28
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
29 my %publicProps = map {$_->Name , 1} __PACKAGE__->get_meta(typeof IMPL::Class::PropertyInfo);
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
30
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
31 __PACKAGE__->class_data(CONTROLLER_METHODS,{});
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
32
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
33 sub CTOR {
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
34 my ($this,$action,$args) = @_;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
35
c13a215508ca Refactoring,
wizard
parents:
diff changeset
36 $this->action($action);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
37 $this->application($action->application);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
38 $this->query($action->query);
144
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 142
diff changeset
39 $this->response($action->response);
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
40
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
41 $this->$_($args->{$_}) foreach qw(formData formSchema formErrors);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
42 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
43
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
44 sub unitNamespace() {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
45 ""
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
46 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
47
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
48 sub transactions {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
49 my ($self,%methods) = @_;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
50
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
51 while (my ($method,$info) = each %methods) {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
52 if ($info and ref $info ne 'HASH') {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
53 warn "Bad transaction $method description";
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
54 $info = {};
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
55 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
56
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
57 $info->{wrapper} = 'TransactionWrapper';
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
58 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
59 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
60 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
61
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
62 sub forms {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
63 my ($self,%forms) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
64
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
65 while ( my ($method,$info) = each %forms ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
66 die new IMPL::Exception("A method doesn't exists in the controller",$self,$method) unless $self->can($method);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
67 if ( not ref $info ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
68 $self->class_data(CONTROLLER_METHODS)->{$method} = {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
69 wrapper => 'FormWrapper',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
70 schema => $info
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
71 };
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
72 } elsif (ref $info eq 'HASH') {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
73 die new IMPL::Exception("A schema must be specified",$self,$method) unless $info->{schema};
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
74
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
75 $self->class_data(CONTROLLER_METHODS)->{$method} = {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
76 wrapper => 'FormWrapper',
142
4c9849f0f879 minor changes
wizard
parents: 138
diff changeset
77 schema => $info->{schema},
4c9849f0f879 minor changes
wizard
parents: 138
diff changeset
78 form => $info->{form}
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
79 };
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
80 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
81 die new IMPL::Exception("Unsupported method information",$self,$method);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
82 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
83 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
84 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
85
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
86 sub InvokeAction {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
87 my ($self,$method,$action) = @_;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
88
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
89 if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
90 if (my $wrapper = $methodInfo->{wrapper}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
91 return $self->$wrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
92 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
93 return $self->TransactionWrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
94 }
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
95 } else {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
96 die new IMPL::InvalidOperationException("Invalid method call",$self,$method);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
97 }
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
98 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
99
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
100 sub MakeParams {
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
101 my ($this,$methodInfo) = @_;
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
102
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
103 my $params;
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
104 if ($params = $methodInfo->{parameters} and ref $params eq 'ARRAY') {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
105 return map $this->ResolveParam($_,$methodInfo->{inflate}{$_}), @$params;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
106 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
107 return();
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
108 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
109
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
110 sub ResolveParam {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
111 my ($this,$param,$inflate) = @_;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
112
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
113 if ( $param =~ /^::(\w+)$/ and $publicProps{$1}) {
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
114 return $this->$1();
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
115 } else {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
116 my $value;
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
117 if ( my $rx = $inflate->{rx} ) {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
118 $value = $this->action->param($param,$rx);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
119 } else {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
120 $value = $this->query->param($param);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
121 }
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
122
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
123 if (my $method = $inflate->{method}) {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
124 $value = $this->$method($value);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
125 }
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
126 return $value;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
127 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
128 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
129
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
130 sub TransactionWrapper {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
131 my ($self,$method,$action,$methodInfo) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
132
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
133 my $unit = $self->new($action);
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
134 return $unit->$method($unit->MakeParams($methodInfo));
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
135 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
136
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
137 sub FormWrapper {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
138 my ($self,$method,$action,$methodInfo) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
139
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
140 my $schema = $self->loadSchema($methodInfo->{schema});
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
141
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
142 my $process = $action->query->param('process') || 0;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
143 my $form = $methodInfo->{form}
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
144 || $action->query->param('form')
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
145 || $schema->selectSingleNode('ComplexNode')->name
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
146 or die new IMPL::Exception('No situable form name could be determined',$self,$method);
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
147
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
148 my %result;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
149
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
150 my $transform = IMPL::DOM::Transform::PostToDOM->new(
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
151 undef,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
152 $schema,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
153 $form
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
154 );
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
155
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 134
diff changeset
156 $result{formName} = $form;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
157 $result{formSchema} = $schema;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
158 $result{formData} = $transform->Transform($action->query);
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
159
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
160
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
161 if ($process) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
162 $result{formErrors} = $transform->Errors->as_list;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
163 if ($transform->Errors->Count) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
164 $result{state} = STATE_INVALID;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
165 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
166 $result{state} = STATE_CORRECT;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
167 my $unit = $self->new($action,\%result);
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
168
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
169 eval {
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
170 $result{result} = $unit->$method($unit->MakeParams($methodInfo));
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
171 };
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
172 if (my $err = $@) {
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
173 $result{state} = STATE_INVALID;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
174 if (eval { $err->isa(typeof IMPL::WrongDataException) } ) {
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
175 $result{formErrors} = $err->Args;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
176 } else {
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
177 die $err;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
178 }
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 126
diff changeset
179 }
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
180 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
181 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
182 $result{state} = STATE_NEW;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
183 }
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
184
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
185 return \%result;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
186 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
187
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
188 sub loadSchema {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
189 my ($self,$name) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
190
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
191 if (-f $name) {
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
192 return IMPL::DOM::Schema->LoadSchema($name);
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
193 } else {
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
194 my ($vol,$dir,$file) = File::Spec->splitpath( Class::Inspector->resolved_filename(ref $self || $self) );
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
195
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
196 return IMPL::DOM::Schema->LoadSchema(File::Spec->catfile($vol,$dir,$name));
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
197 }
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
198 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
199
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
200 sub discover {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
201 my ($this) = @_;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
202
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
203 my $methods = $this->class_data(CONTROLLER_METHODS);
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
204
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
205 my $namespace = $this->unitNamespace;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
206 (my $module = typeof $this) =~ s/^$namespace//;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
207
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
208 my %smd = (
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
209 module => [grep $_, split /::/, $module ],
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
210 );
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
211
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
212 while (my ($method,$info) = each %$methods) {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
213 my %methodInfo = (
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
214 name => $method
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
215 );
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
216 $methodInfo{parameters} = $info->{parameters} if $info->{parameters};
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
217 push @{$smd{methods}},\%methodInfo;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
218 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
219 return \%smd;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
220 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
221
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
222 __PACKAGE__->transactions(
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
223 discover => undef
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
224 );
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
225
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
226 1;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
227
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
228 __END__
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
229
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
230 =pod
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
231
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
232 =head1 NAME
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
233
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
234 C<IMPL::Web::Application::ControllerUnit> - базовый класс для обработчика транзакций в модели контроллера.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
235
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
236 =head1 DESCRIPTION
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
237
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
238 Классы, наследуемые от данного класса называется пакетом транзакций. Часть методов в таком классе
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
239 объявляются как транзакции при помощи методов C<transaction>, C<form>.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
240
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
241 Перед выполнением транзакции создается экземпляр объекта, в рамках которого будет выполнена транзакция.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
242 Для этого вызывается метод C<InvokeAction($method,$action)>, который создает/восстанавливает контекст
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
243 транзакции.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
244
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
245 Транзакции на данный момент делятся на простые и формы. Различные типы транзакций выполняются при помощи
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
246 различных оберток (C<TransactionWrapper> и C<FormWrapper>). Каждая обертка отвечает за конструирование
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
247 экземпляра объекта и вызов метода для выполнения транзакции, а также за возврат результата выполнения.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
248
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
249 =head2 Простые транзакции
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
250
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
251 Простые транзакции получаю только запрос, без предварительной обработки, и возвращенный результат напрямую
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
252 передается пользователю.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
253
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
254 =head2 Формы
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
255
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
256 При использовании форм запрос предварительно обрабатывается, для получения DOM документа с данными формы.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
257 Для постороенния DOM документа используется схема. При этом становятся доступны дополнительные свойства
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
258 C<formData>, C<formSchema>, C<formErrors>.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
259
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
260 Результат выполнения транзакции не возвращается наверх напрямую, а включается в структуру, которая
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
261 выглядит следующим образом
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
262
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
263 =begin code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
264
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
265 {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
266 state => '{ new | correct | invalid }',
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
267 result => $transactionResult,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
268 formData => $formDOM,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
269 formSchema => $formSchema,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
270 formErrors => @errors
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
271 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
272
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
273 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
274
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
275 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
276
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
277 =item C<state>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
278
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
279 Состояние верификации формы.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
280
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
281 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
282
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
283 =item C<new>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
284
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
285 Первоначальное содержимое формы, оно может быть некорректным, но это нормально.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
286 В данном состоянии транзакция обычно не выполняется.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
287
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
288 =item C<correct>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
289
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
290 Данные формы корректны, транзакция выполнена, и ее результат доступен через поле C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
291
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
292 =item C<invalid>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
293
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
294 Содержимое формы не прошло верификацию, ошибки доступны через поле C<formErrors>. Транзакция
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
295 не выполнялась.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
296
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
297 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
298
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
299 =item C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
300
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
301 Результат выполнения транзакции, если конечно таковая выполнялась.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
302
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
303 =item C<formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
304
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
305 ДОМ документ с данными формами. Документ существует всегда, не зависимо от его корректности,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
306 может быть использован для построения формы, уже заполненную параметрами.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
307
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
308 =item C<formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
309
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
310 Схема данных формы, может использоваться для построения динамических форм.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
311
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
312 =item C<formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
313
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
314 Ссылка на массив с ошибками при проверки формы.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
315
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
316 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
317
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
318 =head1 MEMBERS
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
319
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
320 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
321
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
322 =item C<[get] application>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
323
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
324 Объект приложения, которое обрабатывает запрос.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
325
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
326 =item C<[get] query>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
327
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
328 Текущий запрос.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
329
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
330 =item C<[get] response>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
331
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
332 Текущий ответ.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
333
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
334 =item C<[get] formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
335
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
336 C<IMPL::DOM::Document> документ с данныим, если данный запрос является формой.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
337
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
338 =item C<[get] formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
339
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
340 C<IMPL::DOM::Schema> документ со схемой формы данного запроса.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
341
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
342 =item C<[get] formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
343
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
344 Ошибки верификации данных, если таковые были. Обычно при наличии ошибок в форме, транзакция
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
345 не выполняется, а эти ошибки передаются в ответ.
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
346
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
347 =item C<InvokeAction($method,$action)>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
348
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
349 Конструирует контекст выполнения транзакции, может быть переопределен для конструирования контекста по
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
350 своим правилам.
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
351
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
352 =item C<TransactionWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
353
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
354 Обертка для конструирования простых транзакций, может быть переопределен для конструирования контекста по
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
355 своим правилам.
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
356
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
357 =item C<FormWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
358
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
359 Обертка для конструирования форм, может быть переопределен для конструирования контекста по
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
360 своим правилам.
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
361
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
362 =item C<discover()>
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
363
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
364 Метод, опубликованный для вызова контроллером, возвращает описание методов в формате C<Simple Module Definition>.
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
365
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
366 =begin code
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
367
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
368 # SMD structure
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
369 {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
370 module => ['Foo','Bar'],
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
371 methods => [
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
372 {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
373 name => 'search',
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
374 parameters => ['text','limit'] #optional
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
375 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
376 ]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
377 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
378
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
379 =end code
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
380
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
381 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
382
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
383 =head1 EXAMPLE
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
384
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
385 =begin code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
386
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
387 package MyBooksUnit;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
388 use strict;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
389 use base qw(IMPL::Web::Application::ControllerUnit);
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
390
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
391 __PACKAGE__->PassThroughArgs;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
392
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
393 sub unitDataClass { 'My::Books' }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
394
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
395 __PACKAGE__->transactions(
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
396 find => {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
397 parameters => [qw(author)]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
398 },
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
399 info => {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
400 parameters => [qw(id)]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
401 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
402 );
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
403 __PACKAGE__->forms(
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
404 create => 'books.create.xml'
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
405 );
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
406
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
407 sub find {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
408 my ($this,$author) = @_;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
409
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
410 return $this->ds->find({author => $author});
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
411 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
412
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
413 sub info {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
414 my ($this,$id) = @_;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
415
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
416 return $this->ds->find({id => $id});
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
417 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
418
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
419 sub create {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
420 my ($this) = @_;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
421
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
422 my %book = map {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
423 $_->nodeName, $_->nodeValue
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
424 } $this->formData->selectNodes([qw(author_id title year ISBN)]);
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
425
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
426 return $this->ds->create(\%book);
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
427 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
428
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
429 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
430
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
431 =cut