annotate Lib/IMPL/Web/TT/Document.pm @ 220:5c82c15b25b1

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