annotate Lib/IMPL/Web/TT/Document.pm @ 152:1e7f03414b65

DOM: schema improvements DOM: saving to XML::Writer feature
author wizard
date Thu, 23 Sep 2010 03:58:43 +0400
parents 4369d5458bb6
children eb478083f72b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
1 package IMPL::Web::TT::Document;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
4
75
wizard
parents: 49
diff changeset
5 use base qw(IMPL::DOM::Document IMPL::Object::Disposable);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
6 use Template::Context;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
7 use Template::Provider;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
8 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
9 use File::Spec;
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
10 use Scalar::Util qw(blessed);
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
11 use IMPL::Web::TT::Collection;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
12 use IMPL::Web::TT::Control;
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
13 use Carp;
150
4369d5458bb6 minor fixes
wizard
parents: 146
diff changeset
14 use Encode();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
15
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
16 BEGIN {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
17 private property _provider => prop_all;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
18 private property _context => prop_all;
134
44977efed303 Significant performance optimizations
wizard
parents: 127
diff changeset
19 public property cache => prop_all;
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
20 public property template => prop_get | owner_set;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
21 public property presenter => prop_all, { validate => \&_validatePresenter };
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
22 public property preprocess => prop_all | prop_list,
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
23 private property _controlClassMap => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
24 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
25
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
26 our %CTOR = (
75
wizard
parents: 49
diff changeset
27 'IMPL::DOM::Document' => sub { nodeName => 'document' }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
28 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
29
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
30 sub CTOR {
134
44977efed303 Significant performance optimizations
wizard
parents: 127
diff changeset
31 my ($this,%args) = @_;
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
32
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
33 $this->_controlClassMap({});
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
34 $this->registerControlClass( Control => 'IMPL::Web::TT::Control' );
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
35 $this->appendChild( $this->Create(body => 'IMPL::Web::TT::Collection') );
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
36 $this->appendChild( $this->Create(head => 'IMPL::Web::TT::Collection') );
134
44977efed303 Significant performance optimizations
wizard
parents: 127
diff changeset
37 $this->cache($args{cache}) if $args{cache};
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
38 $this->preprocess($args{preprocess}) if $args{preprocess};
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
39 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
40
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
41 sub CreateControl {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
42 my ($this,$name,$class,$args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
43
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
44 $args = {} unless ref $args eq 'HASH';
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
45
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
46 if (my $info = $this->_controlClassMap->{$class}) {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
47 my %nodeArgs = (%{$info->{args}},%$args);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
48 $nodeArgs{controlClass} = $class;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
49
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
50 return $this->Create($name,$info->{type},\%nodeArgs);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
51 } else {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
52 die new IMPL::Exception('A control is\'t registered', $class, $name);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
53 }
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
54 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
55
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
56 sub provider {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
57 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
58
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
59 if (my $provider = $this->_provider) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
60 return $provider;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
61 } else {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
62 return $this->_provider(new Template::Provider(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
63 \%args
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
64 ));
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
65 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
66 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
67
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
68 sub context {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
69 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
70
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
71 if (my $ctx = $this->_context) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
72 return $ctx;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
73 } else {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
74 return $this->_context (
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
75 new Template::Context(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
76 VARIABLES => {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
77 document => $this,
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
78 this => $this,
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
79 render => sub {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
80 $this->_process(@_);
150
4369d5458bb6 minor fixes
wizard
parents: 146
diff changeset
81 },
4369d5458bb6 minor fixes
wizard
parents: 146
diff changeset
82 encode => sub {
4369d5458bb6 minor fixes
wizard
parents: 146
diff changeset
83 Encode::encode('utf8',shift);
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
84 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
85 },
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
86 RECURSION => 1,
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
87 LOAD_TEMPLATES => [$this->provider]
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
88 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
89 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
90 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
91 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
92
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
93 sub resolveVar {
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
94 my ($this,$var) = @_;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
95
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
96 return $this->context->stash->get($var);
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
97 }
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
98
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
99 sub registerControlClass {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
100 my ($this, $controlClass, $type, $args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
101
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
102 $type ||= 'IMPL::Web::TT::Control';
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
103
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
104 die new IMPL::InvalidArgumentException("A controlClass must be a single word",$controlClass) unless $controlClass =~ /^\w+$/;
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
105
117
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
106 eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless eval { $type->can('new') };
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
107
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
108 die new IMPL::InvalidArgumentException("A type must be subclass of IMPL::DOM::Node",$type) unless $type->isa('IMPL::DOM::Node');
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
109
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
110 # resolve template name to a real template
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
111 $args->{template} = $this->context->template($args->{template}) if $args->{template};
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
112
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
113 $this->_controlClassMap->{$controlClass} = {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
114 controlClass => $controlClass,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
115 type => $type,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
116 args => ref $args eq 'HASH' ? $args : {}
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
117 };
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
118 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
119
117
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
120 sub require {
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
121 my ($this,$template) = @_;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
122
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
123 my $doc = $this->context->template($template);
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
124
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
125 die new IMPL::InvalidOperationException("A specified template isn't a document",$template) unless eval{ $doc -> isa('Template::Document') };
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
126
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
127 my $controlClass = $doc->class;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
128 my $type = $doc->nativeType;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
129 my $controlTemplate;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
130 my $out = "";
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
131
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
132 die new IMPL::InvalidOperationException("A specified template isn't a control",$template) unless $controlClass;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
133
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
134 if (not $this->isControlClass($controlClass)) {
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
135 if ($doc->template) {
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
136 $controlTemplate = $doc->blocks()->{$doc->template} || $this->context->template($doc->template);
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
137 $out = $this->context->include($doc);
117
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
138 } else {
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
139 $controlTemplate = $doc;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
140 }
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
141 $this->registerControlClass($controlClass,$type,{ template => $controlTemplate } );
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
142 }
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
143
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
144 return $out;
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
145 }
0475eb382085 Controls support (RC1)
wizard
parents: 109
diff changeset
146
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
147 sub isControlClass {
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
148 my ($this,$name) = @_;
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
149 return $this->_controlClassMap->{$name} ? 1 : 0;
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
150 }
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
151
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
152 sub _getControls {
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
153 my ($this) = @_;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
154
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
155 my ($node) = $this->selectNodes('controls');
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
156 return $node;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
157 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
158
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
159 sub _validatePresenter {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
160 my ($this,$value) = @_;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
161
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
162 die new IMPL::InvalidArgumentException("A view object is required") unless blessed($value) and $value->isa('Template::View');
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
163 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
164
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
165 sub LoadFile {
121
92c850d0bdb9 Minor changes
wizard
parents: 117
diff changeset
166 my ($this,$filePath,$encoding,@includes) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
167
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
168 die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
169
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
170 $encoding ||= 'utf8';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
171
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
172 $this->_context(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
173 $this->_provider(undef);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
174
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
175 my ($vol,$dir,$fileName) = File::Spec->splitpath($filePath);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
176
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
177 my $inc = File::Spec->catpath($vol,$dir,'');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
178
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
179 $this->provider(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
180 ENCODING => $encoding,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
181 INTERPOLATE => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
182 PRE_CHOMP => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
183 POST_CHOMP => 1,
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
184 TRIM => 0,
134
44977efed303 Significant performance optimizations
wizard
parents: 127
diff changeset
185 COMPILE_EXT => $this->cache ? '.ttc' : undef,
44977efed303 Significant performance optimizations
wizard
parents: 127
diff changeset
186 COMPILE_DIR => $this->cache,
121
92c850d0bdb9 Minor changes
wizard
parents: 117
diff changeset
187 INCLUDE_PATH => [$inc,@includes]
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
188 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
189
146
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
190 $this->context->process($_) foreach $this->preprocess;
60fd224f3e3c fixed cgi parameters processing
wizard
parents: 145
diff changeset
191
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
192 $this->template($this->context->template($fileName));
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
193 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
194
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
195 sub AddVar {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
196 my ($this,$name,$value) = @_;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
197
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
198 $this->context->stash->set($name,$value);
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
199 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
200
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
201 sub title {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
202 $_[0]->template->title;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
203 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
204
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
205 sub Render {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
206 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
207
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
208 return $this->template->process($this->context);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
209 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
210
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
211 # Формирует представление для произвольных объектов
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
212 sub _process {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
213 my ($this,@items) = @_;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
214
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
215 my @result;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
216
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
217 foreach my $item (@items) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
218 if (blessed($item) and $item->isa('IMPL::Web::TT::Control')) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
219 push @result, $item->Render();
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
220 } elsif(blessed($item)) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
221 if ($this->presenter) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
222 push @result, $this->presenter->print($item);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
223 } else {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
224 push @result, $this->toString;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
225 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
226 } else {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
227 push @result, $item;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
228 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
229 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
230
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
231 return join '',@result;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
232 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
233
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
234 our $AUTOLOAD;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
235 sub AUTOLOAD {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
236 my $this = shift;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
237 my ($method) = ($AUTOLOAD =~ /(\w+)$/);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
238
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
239 if($method =~ /^create(\w+)/) {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
240 my ($name,$args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
241 return $this->CreateControl($name,$1,$args);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
242 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
243
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
244 my @result = $this->selectNodes($method);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
245
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
246 return $result[0] if @result;
109
ddf0f037d460 IMPL::DOM::Node updated to support TT, (added childNodesRef and selectNodesRef for using from TT)
wizard
parents: 108
diff changeset
247 carp "Looks like you have a mistake, document doesn't have a such property or child: $method";
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
248 return;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
249 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
250
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
251 sub as_list {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
252 $_[0]->childNodes;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
253 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
254
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
255 sub Dispose {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
256 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
257
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
258 $this->template(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
259 $this->_context(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
260 $this->_provider(undef);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
261
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
262 $this->supercall::Dispose();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
263 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
264
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
265 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
266 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
267 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
268
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
269 =head1 NAME
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
270
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
271 C<IMPL::Web::TT::Document> - Документ, позволяющий строить представление по шаблону
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
272
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
273 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
274
75
wizard
parents: 49
diff changeset
275 =begin code
wizard
parents: 49
diff changeset
276
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
277 // create new document
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
278 my $doc = new IMPL::Web::TT::Document;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
279
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
280 // load template
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
281 $doc->loadFile('Templates/index.tt');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
282
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
283 // render file
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
284 print $doc->Render();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
285
75
wizard
parents: 49
diff changeset
286 =end code
wizard
parents: 49
diff changeset
287
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
288 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
289
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
290 C<use base qw(IMPL::DOM::Document)>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
291
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
292 Документ, основанный на шаблоне Template::Toolkit. Позволяет загрузить шаблон,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
293 и сформировать окончательный документ. Является наследником C<IMPL::DOM::Node>,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
294 т.о. может быть использован для реализации DOM модели.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
295
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
296 Внутри шаблона переменная C<document> ссылается на объект документа. По этой
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
297 причине образуется циклическая ссылка между объектами шаблона и документом, что
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
298 требует вызова метода C<Dispose> для освобождения документа.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
299
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
300 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
301
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
302 =over
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
303
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
304 =item C<CTOR()>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
305
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
306 Создает новый экземпляр документа, свойство C<nodeName> устанавливается в 'C<document>'
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
307
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
308 =item C<$doc->LoadFile($fileName,$encoding)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
309
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
310 Загружает шаблон из файла C<$fileName>, используя кодировку C<$encoding>. Если
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
311 кодировка не указана, использует utf-8.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
312
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
313 =item C<$doc->Render()>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
314
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
315 Возвращает данные построенные на основе загруженного шаблона.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
316
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
317 =item C<$doc->Dispose()>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
318
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
319 Освобождает ресурсы и помечает объект как освобожденный.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
320
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
321 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
322
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
323 =head1 DOM
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
324
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
325 Документ представляет собой DOM документ, состоящий из узлов, которые представляют собой данные
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
326 для отображения. Для форматированого вывода используется C<template>.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
327
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
328 В качестве элементов документа могут присутсвовать специальные объекты C<IMPL::Web::TT::Control>,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
329 которые внутри содержат шаблон для форматирования собственного содержимого.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
330
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
331
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
332
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
333 Документ предоставляет ряд фнукций для работы с элементами управления.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
334
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
335 =head1 TEMPLATE
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
336
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
337 =begin code html
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
338
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
339 [% CALL document.registerClass( 'Table', 'My::TableClass', template => 'tables/pretty.tt' ) %]
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
340 [% CALL document.registerClass( 'Form' )%]
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
341
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
342 [% table = document.сreateTable('env') %]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
343
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
344 [% FOEACH item in document.result %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
345 [% table.rows.Add( item.get('name','value') ) %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
346 [% END %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
347
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
348 [% form = document.createForm('login') %]
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
349 [% form.template = 'LOGIN_FORM'%]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
350
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
351 [% FOREACH item IN document.childNodes %]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
352 [%render(item)%]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
353 [% END %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
354
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
355 [% BLOCK LOGIN_FORM %]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
356 <form method="POST" action='/login.pl'>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
357 user: [% render(this.item('name')) %] password: [% render(this.item('password')) %] <input type="submit"/>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
358 </form>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
359 [% END %]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
360
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
361 =end code html
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
362
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
363 =cut