annotate Lib/IMPL/Web/TT/Document.pm @ 108:c6fb6964de4c

Removed absolute modules Updated DOM model, selectNodes can now select a complex path Web DOM model release candidate
author wizard
date Fri, 14 May 2010 16:06:06 +0400
parents 0e72ad99eef7
children ddf0f037d460
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;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
13
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
14 BEGIN {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
15 private property _provider => prop_all;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
16 private property _context => prop_all;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
17 public property template => prop_get | owner_set;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
18 public property presenter => prop_all, { validate => \&_validatePresenter };
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
19 private property _controlClassMap => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
20 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
21
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
22 our %CTOR = (
75
wizard
parents: 49
diff changeset
23 'IMPL::DOM::Document' => sub { nodeName => 'document' }
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
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
26 sub CTOR {
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
27 my ($this) = @_;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
28
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
29 $this->_controlClassMap({});
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
30 $this->registerControlClass( Control => 'IMPL::Web::TT::Control' );
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
31 $this->appendChild( $this->Create(body => 'IMPL::Web::TT::Collection') );
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
32 $this->appendChild( $this->Create(head => 'IMPL::Web::TT::Collection') );
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
33 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
34
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
35 sub CreateControl {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
36 my ($this,$name,$class,$args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
37
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
38 $args = {} unless ref $args eq 'HASH';
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
39
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
40 if (my $info = $this->_controlClassMap->{$class}) {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
41 my %nodeArgs = (%{$info->{args}},%$args);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
42 $nodeArgs{controlClass} = $class;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
43
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
44 return $this->Create($name,$info->{type},\%nodeArgs);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
45 } else {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
46 die new IMPL::Exception('A control is\'t registered', $class, $name);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
47 }
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
48 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
49
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
50 sub provider {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
51 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
52
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
53 if (my $provider = $this->_provider) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
54 return $provider;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
55 } else {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
56 return $this->_provider(new Template::Provider(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
57 \%args
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
58 ));
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
59 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
60 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
61
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
62 sub context {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
63 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
64
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
65 if (my $ctx = $this->_context) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
66 return $ctx;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
67 } else {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
68 return $this->_context (
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
69 new Template::Context(
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
70 VARIABLES => {
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
71 document => $this,
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
72 this => $this,
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
73 render => sub {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
74 $this->_process(@_);
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
75 }
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
76 },
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
77 TRIM => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
78 RECURSION => 1,
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
79 LOAD_TEMPLATES => [$this->provider]
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
80 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
81 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
82 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
83 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
84
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
85 sub registerControlClass {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
86 my ($this, $controlClass, $type, $args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
87
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
88 $type ||= 'IMPL::Web::TT::Control';
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
89
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
90 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
91
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
92 eval "require $type; 1;" or die new IMPL::Exception("Failed to load a module",$type,"$@") unless ref $type or $INC{$type};
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
93
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
94 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
95
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
96 $this->_controlClassMap->{$controlClass} = {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
97 controlClass => $controlClass,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
98 type => $type,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
99 args => ref $args eq 'HASH' ? $args : {}
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
100 };
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
101 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
102
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
103 sub _getControls {
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
104 my ($this) = @_;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
105
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
106 my ($node) = $this->selectNodes('controls');
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
107 return $node;
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
108 }
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
109
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
110 sub _validatePresenter {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
111 my ($this,$value) = @_;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
112
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
113 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
114 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
115
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
116 sub LoadFile {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
117 my ($this,$filePath,$encoding) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
118
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
119 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
120
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
121 $encoding ||= 'utf8';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
122
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
123 $this->_context(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
124 $this->_provider(undef);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
125
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
126 my ($vol,$dir,$fileName) = File::Spec->splitpath($filePath);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
127
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
128 my $inc = File::Spec->catpath($vol,$dir,'');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
129
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
130 $this->provider(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
131 ENCODING => $encoding,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
132 INTERPOLATE => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
133 PRE_CHOMP => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
134 POST_CHOMP => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
135 INCLUDE_PATH => $inc
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
136 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
137
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
138 $this->template($this->context->template($fileName));
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
139 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
140
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
141 sub AddVar {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
142 my ($this,$name,$value) = @_;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
143
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
144 $this->context->stash->set($name,$value);
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
145 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
146
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
147 sub title {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
148 $_[0]->template->title;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
149 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
150
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
151 sub Render {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
152 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
153
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
154 return $this->template->process($this->context);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
155 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
156
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
157 # Формирует представление для произвольных объектов
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
158 sub _process {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
159 my ($this,@items) = @_;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
160
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
161 my @result;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
162
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
163 foreach my $item (@items) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
164 if (blessed($item) and $item->isa('IMPL::Web::TT::Control')) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
165 push @result, $item->Render();
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
166 } elsif(blessed($item)) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
167 if ($this->presenter) {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
168 push @result, $this->presenter->print($item);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
169 } else {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
170 push @result, $this->toString;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
171 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
172 } else {
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
173 push @result, $item;
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
174 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
175 }
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
176
107
0e72ad99eef7 Updated Web::TT
wizard
parents: 97
diff changeset
177 return join '',@result;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
178 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
179
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
180 our $AUTOLOAD;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
181 sub AUTOLOAD {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
182 my $this = shift;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
183 my ($method) = ($AUTOLOAD =~ /(\w+)$/);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
184
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
185 if($method =~ /^create(\w+)/) {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
186 my ($name,$args) = @_;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
187 return $this->CreateControl($name,$1,$args);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
188 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
189
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
190 my @result = $this->selectNodes($method);
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
191
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
192 return $result[0] if @result;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
193 return;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
194 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
195
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
196 sub as_list {
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
197 $_[0]->childNodes;
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
198 }
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
199
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
200 sub Dispose {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
201 my ($this) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
202
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
203 $this->template(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
204 $this->_context(undef);
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
205 $this->_provider(undef);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
206
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
207 $this->supercall::Dispose();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
208 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
209
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
210 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
211 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
212 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
213
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
214 =head1 NAME
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
215
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
216 C<IMPL::Web::TT::Document> - Документ, позволяющий строить представление по шаблону
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
217
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
218 =head1 SYNOPSIS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
219
75
wizard
parents: 49
diff changeset
220 =begin code
wizard
parents: 49
diff changeset
221
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
222 // create new document
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
223 my $doc = new IMPL::Web::TT::Document;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
224
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
225 // load template
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
226 $doc->loadFile('Templates/index.tt');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
227
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
228 // render file
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
229 print $doc->Render();
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
230
75
wizard
parents: 49
diff changeset
231 =end code
wizard
parents: 49
diff changeset
232
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
233 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
234
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
235 C<use base qw(IMPL::DOM::Document)>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
236
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
237 Документ, основанный на шаблоне Template::Toolkit. Позволяет загрузить шаблон,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
238 и сформировать окончательный документ. Является наследником C<IMPL::DOM::Node>,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
239 т.о. может быть использован для реализации DOM модели.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
240
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
241 Внутри шаблона переменная C<document> ссылается на объект документа. По этой
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
242 причине образуется циклическая ссылка между объектами шаблона и документом, что
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
243 требует вызова метода C<Dispose> для освобождения документа.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
244
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
245 =head1 METHODS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
246
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
247 =over
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
248
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
249 =item C<CTOR()>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
250
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
251 Создает новый экземпляр документа, свойство C<nodeName> устанавливается в 'C<document>'
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
252
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
253 =item C<$doc->LoadFile($fileName,$encoding)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
254
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
255 Загружает шаблон из файла C<$fileName>, используя кодировку C<$encoding>. Если
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
256 кодировка не указана, использует utf-8.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
257
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
258 =item C<$doc->Render()>
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
259
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
260 Возвращает данные построенные на основе загруженного шаблона.
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
261
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
262 =item C<$doc->Dispose()>
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
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
266 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
267
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
268 =head1 DOM
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
269
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
270 Документ представляет собой DOM документ, состоящий из узлов, которые представляют собой данные
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
271 для отображения. Для форматированого вывода используется C<template>.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
272
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
273 В качестве элементов документа могут присутсвовать специальные объекты C<IMPL::Web::TT::Control>,
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
274 которые внутри содержат шаблон для форматирования собственного содержимого.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
275
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
276
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
277
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
278 Документ предоставляет ряд фнукций для работы с элементами управления.
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
279
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
280 =head1 TEMPLATE
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
281
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
282 =begin code html
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
283
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
284 [% CALL document.registerClass( 'Table', 'My::TableClass', template => 'tables/pretty.tt' ) %]
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
285 [% CALL document.registerClass( 'Form' )%]
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
286
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
287 [% table = document.сreateTable('env') %]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
288
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
289 [% FOEACH item in document.result %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
290 [% table.rows.Add( item.get('name','value') ) %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
291 [% END %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
292
108
c6fb6964de4c Removed absolute modules
wizard
parents: 107
diff changeset
293 [% form = document.createForm('login') %]
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
294 [% form.template = 'LOGIN_FORM'%]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
295
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
296 [% FOREACH item IN document.childNodes %]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
297 [%render(item)%]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
298 [% END %]
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
299
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
300 [% BLOCK LOGIN_FORM %]
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
301 <form method="POST" action='/login.pl'>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
302 user: [% render(this.item('name')) %] password: [% render(this.item('password')) %] <input type="submit"/>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
303 </form>
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
304 [% END %]
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
305
77
9d24db321029 Refactoring Web::TT
wizard
parents: 76
diff changeset
306 =end code html
76
b1652a158b2b Web::DOM
wizard
parents: 75
diff changeset
307
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 7
diff changeset
308 =cut