annotate Lib/IMPL/Web/View/TTDocument.pm @ 309:5e4e7c8fbca1

sync
author cin
date Fri, 19 Apr 2013 00:27:51 +0400
parents 47a09a8dc23a
children 0a9d51cf6dfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
1 package IMPL::Web::View::TTDocument;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
2 use strict;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
3
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
4 use Scalar::Util qw(weaken);
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
5 use IMPL::Const qw(:prop);
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
6 use IMPL::lang qw(:hash is);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
7 use Carp qw(carp);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
8 use mro;
309
cin
parents: 308
diff changeset
9 use IMPL::Exception();
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
10 use IMPL::declare {
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
11 require => {
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
12 TTRegistry => 'IMPL::Web::View::TTRegistry',
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
13 TTFactory => 'IMPL::Web::View::TTFactory',
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
14 TTControl => 'IMPL::Web::View::TTControl',
309
cin
parents: 308
diff changeset
15 Loader => 'IMPL::Code::Loader',
cin
parents: 308
diff changeset
16 OpException => '-IMPL::InvalidOperationException'
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
17 },
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
18 base => [
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
19 'IMPL::Web::View::TTControl' => sub {
309
cin
parents: 308
diff changeset
20 my ($template,$ctx,$vars) = @_;
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
21 $ctx ||= Template::Context->new();
309
cin
parents: 308
diff changeset
22 return $template, $ctx, $vars; # context
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
23 }
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
24 ],
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
25 props => [
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
26 layout => PROP_RW,
307
2da2564f115d *TTView: fixed memory leak
cin
parents: 305
diff changeset
27 baseLocation => PROP_RW
236
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
28 ]
2904da230022 DOM refactoring
sergey
parents: 234
diff changeset
29 };
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
30
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
31 sub CTOR {
308
sergey
parents: 307
diff changeset
32 my ($this,$template,$ctx,$vars) = @_;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
33
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
34 $this->layout( $template->layout ) unless $this->layout;
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
35 $this->title( $template->title ) unless $this->title;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
36
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
37 $this->context->stash->update($vars)
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
38 if ref $vars eq 'HASH';
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
39 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
40
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
41 sub Render {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
42 my ($this,$args) = @_;
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
43
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
44 $args ||= {};
290
7b0dad6117d5 *TTView: fixed memory leak
sergey
parents: 289
diff changeset
45
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
46 $this->context->localise(); # localise stash
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
47 my $documentContext = _clone_context( $this->context ); # create a new context
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
48
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
49 $this->context->stash->update({
307
2da2564f115d *TTView: fixed memory leak
cin
parents: 305
diff changeset
50 document => sub { $this }
305
b5d5793f348e TTView refactoring, still experiencing memory leaks
sergey
parents: 304
diff changeset
51 });
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
52
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
53 my $text = eval {
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
54
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
55 if ($this->layout) {
309
cin
parents: 308
diff changeset
56 my $tlayout = $this->registry->loader->layout($this->layout)
cin
parents: 308
diff changeset
57 or die OpException->new('The specified layout isn\'t found', $this->layout);
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
58 if(my $init = $tlayout->blocks->{INIT}) {
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
59 $this->context->process(
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
60 $init,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
61 hashMerge(
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
62 $args,
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
63 {
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
64 template => $this->template
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
65 }
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
66 )
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
67 );
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
68 }
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
69 my $content = $this->next::method($args);
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
70 return $this->context->include(
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
71 $tlayout,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
72 {
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
73 %{$args},
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
74 content => $content,
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
75 this => $this,
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
76 template => $this->template
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
77 }
286
d357b5d85d25 *TTView refactoring
sergey
parents: 285
diff changeset
78 );
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
79 } else {
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
80 return $this->next::method($args);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
81 }
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
82 };
301
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
83
aeeb57a12046 *IMPL::Web::View: templates inheritance support
cin
parents: 300
diff changeset
84 my $e = $@;
289
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
85
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
86 $this->context->delocalise();
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
87
307
2da2564f115d *TTView: fixed memory leak
cin
parents: 305
diff changeset
88 undef $this;
2da2564f115d *TTView: fixed memory leak
cin
parents: 305
diff changeset
89
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
90 if ($e) {
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
91 die $e;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
92 } else {
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
93 return $text;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 193
diff changeset
94 }
190
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
95 }
cd1ff7029a63 IMLP::Web::View refactored, added new method 'require' which is available inside templates. Changed document rendering.
cin
parents: 189
diff changeset
96
303
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
97 sub GetTemplate {
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
98 my ($this,$name) = @_;
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
99
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
100 $this->template->blocks->{$name};
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
101 }
a5eb64c6e6f7 TTDocument.GetTemplate corrected to work with document blocks
cin
parents: 301
diff changeset
102
308
sergey
parents: 307
diff changeset
103 sub DTOR {
sergey
parents: 307
diff changeset
104 my $this = shift;
sergey
parents: 307
diff changeset
105
sergey
parents: 307
diff changeset
106 $this->registry->Dispose() if $this->registry;
sergey
parents: 307
diff changeset
107 }
sergey
parents: 307
diff changeset
108
289
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
109 sub _clone_context {
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
110 my $args = { %{shift || {}} };
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
111 delete $args->{CONFIG};
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
112
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
113 return Template::Context->new($args);
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
114 }
85572f512abc *TTView refactoring
cin
parents: 288
diff changeset
115
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
120 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
121
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
122 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
123
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
124 C<IMPL::Web::View::TTDocument> - документ для построения HTML страницы на основе шаблонов TT.
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
125
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
126 =head1 SYNOPSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
127
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
128 =begin code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
129
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
130
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
131 =end code
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
132
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
133 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
134
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
135
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
136 =over
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
137
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
138
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
139 =cut