annotate Lib/IMPL/Web/Application/ControllerUnit.pm @ 171:59e5fcb59d86

Исправления, изменена концепция веб-форм
author sourcer
date Mon, 06 Jun 2011 03:30:36 +0400
parents b88b7fe60aa3
children 068acfe903c3
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;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 160
diff changeset
3 use parent qw(IMPL::Object);
110
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
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
29 my %publicProps = map {$_->Name , 1} __PACKAGE__->get_meta(typeof IMPL::Class::PropertyInfo);
133
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
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
33 our @schemaInc;
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
34
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
35 sub CTOR {
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
36 my ($this,$action,$args) = @_;
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
37
c13a215508ca Refactoring,
wizard
parents:
diff changeset
38 $this->action($action);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
39 $this->application($action->application);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
40 $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
41 $this->response($action->response);
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
42
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
43 $this->$_($args->{$_}) foreach qw(formData formSchema formErrors);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
44 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
45
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
46 sub unitNamespace() {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
47 ""
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
48 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
49
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
50 sub transactions {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
51 my ($self,%methods) = @_;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
52
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
53 while (my ($method,$info) = each %methods) {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
54 if ($info and ref $info ne 'HASH') {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
55 warn "Bad transaction $method description";
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
56 $info = {};
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
57 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
58
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
59 $info->{wrapper} = 'TransactionWrapper';
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
60 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
61 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
62 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
63
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
64 sub forms {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
65 my ($self,%forms) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
66
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
67 while ( my ($method,$info) = each %forms ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
68 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
69 if ( not ref $info ) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
70 $self->class_data(CONTROLLER_METHODS)->{$method} = {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
71 wrapper => 'FormWrapper',
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
72 schema => $info
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
73 };
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
74 } elsif (ref $info eq 'HASH') {
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 146
diff changeset
75 $info->{wrapper} = 'FormWrapper';
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 146
diff changeset
76
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 146
diff changeset
77 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
78 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
79 die new IMPL::Exception("Unsupported method information",$self,$method);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
80 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
81 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
82 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
83
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
84 sub InvokeAction {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
85 my ($self,$method,$action) = @_;
c13a215508ca Refactoring,
wizard
parents:
diff changeset
86
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
87 if (my $methodInfo = $self->class_data(CONTROLLER_METHODS)->{$method}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
88 if (my $wrapper = $methodInfo->{wrapper}) {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
89 return $self->$wrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
90 } else {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
91 return $self->TransactionWrapper($method,$action,$methodInfo);
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
92 }
110
c13a215508ca Refactoring,
wizard
parents:
diff changeset
93 } else {
c13a215508ca Refactoring,
wizard
parents:
diff changeset
94 die new IMPL::InvalidOperationException("Invalid method call",$self,$method);
c13a215508ca Refactoring,
wizard
parents:
diff changeset
95 }
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
96 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
97
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
98 sub MakeParams {
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
99 my ($this,$methodInfo) = @_;
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
100
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
101 my $params;
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
102 if ($params = $methodInfo->{parameters} and ref $params eq 'ARRAY') {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
103 return map $this->ResolveParam($_,$methodInfo->{inflate}{$_}), @$params;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
104 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
105 return();
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
106 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
107
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
108 sub ResolveParam {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
109 my ($this,$param,$inflate) = @_;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
110
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
111 if ( $param =~ /^::(\w+)$/ and $publicProps{$1}) {
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
112 return $this->$1();
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
113 } else {
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
114 my $value;
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
115 if ( my $rx = $inflate->{rx} ) {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
116 $value = $this->action->param($param,$rx);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
117 } else {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
118 $value = $this->query->param($param);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
119 }
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
120
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
121 if (my $method = $inflate->{method}) {
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
122 $value = $this->$method($value);
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
123 }
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 144
diff changeset
124 return $value;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
125 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
126 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
127
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
128 sub TransactionWrapper {
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
129 my ($self,$method,$action,$methodInfo) = @_;
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
130
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
131 my $unit = $self->new($action);
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
132 return $unit->$method($unit->MakeParams($methodInfo));
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
133 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
134
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
135 sub FormWrapper {
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
136 my ($self,$method,$action,$methodInfo) = @_;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
137
171
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
138 my $schema = $methodInfo->{schema} ? $self->loadSchema($methodInfo->{schema}) : $self->unitSchema;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
139
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
140 my $process = $action->query->param('process') || 0;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
141 my $form = $methodInfo->{form}
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
142 || $action->query->param('form')
171
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
143 || $method;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
144
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
145 my %result;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
146
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
147 my $transform = IMPL::DOM::Transform::PostToDOM->new(
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
148 undef,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
149 $schema,
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
150 $form
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
151 );
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
152
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 134
diff changeset
153 $result{formName} = $form;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
154 $result{formSchema} = $schema;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
155
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
156 if ($process) {
171
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
157 $result{formData} = $transform->Transform($action->query);
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
158 $result{formErrors} = $transform->Errors->as_list;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
159 if ($transform->Errors->Count) {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
160 $result{state} = STATE_INVALID;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
161 } else {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
162 $result{state} = STATE_CORRECT;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
163 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
164
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
165 eval {
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
166 $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
167 };
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 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
169 $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
170 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
171 $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
172 } 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
173 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
174 }
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 }
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
176 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
177 } else {
171
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
178 if (my $initMethod = $methodInfo->{init}) {
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
179 my $unit = $self->new($action,\%result);
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
180 $result{formData} = $transform->Transform( $unit->$initMethod($unit->MakeParams($methodInfo)) );
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
181 } else {
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
182 $result{formData} = $transform->Transform($action->query);
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
183 }
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
184
59e5fcb59d86 Исправления, изменена концепция веб-форм
sourcer
parents: 170
diff changeset
185 $result{formErrors} = $transform->Errors->as_list;
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
186 $result{state} = STATE_NEW;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
187 }
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
188
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
189 return \%result;
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
190 }
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
191
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
192 sub loadSchema {
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
193 my ($self,$name) = @_;
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
194
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
195 foreach my $path (map File::Spec->catfile($_,$name) ,@schemaInc) {
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
196 return IMPL::DOM::Schema->LoadSchema($path) if -f $path;
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
197 }
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
198
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
199 die new IMPL::Exception("A schema isn't found", $name);
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
200 }
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
201
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
202 sub unitSchema {
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
203 my ($self) = @_;
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
204
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
205 my $class = ref $self || $self;
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
206
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
207 my @parts = split(/:+/, $class);
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
208
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
209 my $file = pop @parts;
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
210 $file = "${file}.schema.xml";
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
211
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
212 foreach my $inc ( @schemaInc ) {
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
213 my $path = File::Spec->catfile($inc,@parts,$file);
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
214
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
215 return IMPL::DOM::Schema->LoadSchema($path) if -f $path;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 113
diff changeset
216 }
170
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
217
b88b7fe60aa3 refactoring
sourcer
parents: 166
diff changeset
218 return undef;
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
219 }
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
220
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
221 sub discover {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
222 my ($this) = @_;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
223
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
224 my $methods = $this->class_data(CONTROLLER_METHODS);
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
225
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
226 my $namespace = $this->unitNamespace;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
227 (my $module = typeof $this) =~ s/^$namespace//;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
228
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
229 my %smd = (
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
230 module => [grep $_, split /::/, $module ],
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
231 );
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
232
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
233 while (my ($method,$info) = each %$methods) {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
234 my %methodInfo = (
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
235 name => $method
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
236 );
160
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
237 $methodInfo{parameters} = [ grep /^[^\:]/, @{ $info->{parameters} } ] if ref $info->{parameters} eq 'ARRAY';
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
238 push @{$smd{methods}},\%methodInfo;
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
239 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
240 return \%smd;
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
241 }
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
242
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
243 __PACKAGE__->transactions(
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
244 discover => undef
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
245 );
133
a07a66fd8d5c Added IMPL::Class::MethodInfo
wizard
parents: 132
diff changeset
246
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
247 1;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
248
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
249 __END__
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
250
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
251 =pod
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
252
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
253 =head1 NAME
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
254
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
255 C<IMPL::Web::Application::ControllerUnit> - .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
256
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
257 =head1 DESCRIPTION
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
258
113
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
259 , .
7b14e0122b79 Updated PostToDOM transformation
wizard
parents: 112
diff changeset
260 C<transaction>, C<form>.
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 C<InvokeAction($method,$action)>, /
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
264 .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
265
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
266 .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
267 (C<TransactionWrapper> C<FormWrapper>).
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
268 , .
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
269
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
270 =head2
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 .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
274
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
275 =head2
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
276
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
277 , DOM .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
278 DOM .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
279 C<formData>, C<formSchema>, C<formErrors>.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
280
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
281 , ,
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
282
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
283
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
284 =begin code
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 state => '{ new | correct | invalid }',
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
288 result => $transactionResult,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
289 formData => $formDOM,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
290 formSchema => $formSchema,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
291 formErrors => @errors
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
292 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
293
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
294 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
295
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
296 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
297
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
298 =item C<state>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
299
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 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
303
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
304 =item C<new>
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
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
309 =item C<correct>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
310
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
311 , , C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
312
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
313 =item C<invalid>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
314
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
315 , C<formErrors>.
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
316 .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
317
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
318 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
319
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
320 =item C<result>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
321
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
322 , .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
323
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
324 =item C<formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
325
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
326 . , ,
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
327 , .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
328
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
329 =item C<formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
330
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
331 , .
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
332
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
333 =item C<formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
334
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
335 .
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
336
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
337 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
338
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
339 =head1 MEMBERS
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
340
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
341 =over
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
342
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
343 =item C<[get] application>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
344
128
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<[get] query>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
348
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
349 .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
350
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
351 =item C<[get] response>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
352
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
353 .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
354
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
355 =item C<[get] formData>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
356
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
357 C<IMPL::DOM::Document> , .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
358
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
359 =item C<[get] formSchema>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
360
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
361 C<IMPL::DOM::Schema> .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
362
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
363 =item C<[get] formErrors>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
364
128
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
365 , . ,
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
366 , .
08753833173d Fixed a error handling issue in JSON output: errors are correctly transfered
wizard
parents: 127
diff changeset
367
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
368 =item C<InvokeAction($method,$action)>
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
369
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
370 ,
112
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
371 .
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
372
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
373 =item C<TransactionWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
374
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
375 ,
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
376 .
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
377
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
378 =item C<FormWrapper($method,$action,$methodInfo)>
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
379
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
380 ,
0ed8e2541b1c Form processing mechanism
wizard
parents: 111
diff changeset
381 .
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
382
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
383 =item C<discover()>
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
384
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
385 , , C<Simple Module Definition>.
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
386
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
387 =begin code
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
388
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
389 # SMD structure
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
390 {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
391 module => ['Foo','Bar'],
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
392 methods => [
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
393 {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
394 name => 'search',
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
395 parameters => ['text','limit'] #optional
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
396 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
397 ]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
398 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
399
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
400 =end code
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
401
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
402 =back
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
403
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
404 =head1 EXAMPLE
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
405
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
406 =begin code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
407
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
408 package MyBooksUnit;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
409 use strict;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 160
diff changeset
410 use parent qw(IMPL::Web::Application::ControllerUnit);
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
411
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
412 __PACKAGE__->PassThroughArgs;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
413
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
414 sub unitDataClass { 'My::Books' }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
415
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
416 __PACKAGE__->transactions(
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
417 find => {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
418 parameters => [qw(author)]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
419 },
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
420 info => {
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
421 parameters => [qw(id)]
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
422 }
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
423 );
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
424 __PACKAGE__->forms(
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
425 create => 'books.create.xml'
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
426 );
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
427
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
428 sub find {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
429 my ($this,$author) = @_;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
430
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
431 return $this->ds->find({author => $author});
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
432 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
433
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
434 sub info {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
435 my ($this,$id) = @_;
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
436
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
437 return $this->ds->find({id => $id});
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
438 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
439
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
440 sub create {
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
441 my ($this) = @_;
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
442
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
443 my %book = map {
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
444 $_->nodeName, $_->nodeValue
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
445 } $this->formData->selectNodes([qw(author_id title year ISBN)]);
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
446
134
44977efed303 Significant performance optimizations
wizard
parents: 133
diff changeset
447 return $this->ds->create(\%book);
111
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
448 }
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
449
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
450 =end code
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
451
6c25ea91c985 ControllerUnit concept
wizard
parents: 110
diff changeset
452 =cut