annotate Lib/IMPL/Web/View/TTControl.pm @ 187:927653d01f4f

TTControl::AUTOLOAD now accesses nodeProperties Added TTControl::renderBlock property to access RENDER block of the template
author sergey
date Tue, 03 Apr 2012 07:54:25 +0400
parents 6c0fee769b0c
children 029c9610528c
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::TTControl;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
2 use strict;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
3
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
4 use IMPL::DOM::Property qw(_dom);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
5 use IMPL::lang qw(:declare :constants);
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
6
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
7 use Template::Context();
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
8
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
9 use parent qw(
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
10 IMPL::DOM::Node
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
11 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
12
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
13 {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
14 my $nextId = 1;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
15 sub _GetNextId {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
16 return $nextId++;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
17 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
18 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
19
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
20
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
21 BEGIN {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22 public _dom property id => PROP_ALL;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
23
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
24 public property context => PROP_GET | PROP_OWNERSET;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
25 public property template => PROP_ALL;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
26 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
27
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
28
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
29 sub CTOR {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
30 my ($this,$name,$template,$context,$refProps) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
31
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
32 $name ||= "control";
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
33
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
34 $this->template( $template ) or die new IMPL::ArgumentException("A template is required");
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
35 $this->context( $context ) or die new IMPL::ArgumentException("A context is required");
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
36
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
37 if ( my $ctor = $template->blocks->{CTOR} ) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
38 $context->process($ctor, { this => $this } );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
39 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
40
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
41 $this->id($name . "-" . _GetNextId()) unless $this->id;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
42
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
43 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
44
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
45 our %CTOR = (
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
46 'IMPL::DOM::Node' => sub {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
47 nodeName => $_[0],
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
48 %{ $_[3] || {} }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
49 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
50 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
51
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
52 sub templateVars {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
53 my $this = shift;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
54 my $name = shift;
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
55
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
56 if (@_) {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
57 return $this->context->stash->set($name, shift);
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
58 } else {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
59 return $this->context->stash->get($name);
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
60 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
61 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
62
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
63 sub renderBlock {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
64 $_[0]->template->blocks->{RENDER};
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
65 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
66
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
67 sub Render {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
68 my ($this,$args) = @_;
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
69
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
70 $args = {} unless ref $args eq 'HASH';
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
71
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
72 if(my $body = $this->renderBlock ) {
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
73 return $this->context->include( $body, { %$args, this => $this, template => $this->template } );
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
74 } else {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75 return "";
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
76 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
77 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
78
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
79 sub AUTOLOAD {
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
80 our $AUTOLOAD;
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
81
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
82 my $method = ($AUTOLOAD =~ m/(\w+)$/)[0];
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
83
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
84 return if $method eq 'DESTROY';
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
85
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
86 my $this = shift;
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
87
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
88 $this->nodeProperty(@_);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99 C<IMPL::Web::View::TTControl>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
100
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
101 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
102
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
103 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
104
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
105 =head2 BLOCKS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
106
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
107 При загрузке шаблона, создается фабрика, с собственным контекстом в которой выполняется шаблон элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
108
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109 =head3 INIT
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
111 Данный блок шаблона управления выполняется один раз при создании первого экземпляра элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
112
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
113 =head3 CTOR
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
114
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115 данный блок выполняется каждый раз при создании нового экземпляра элемента управления, при этом переменная C<this>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116 указывает на эземпляр элемента упарвления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118 =head3 RENDER
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
120 Данный блок выполняется при вызове метода C<Render()>, вывод данного блока и есть результат отображения элемента управления.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
121
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
122 =head2 TEMPLATE VARS
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
123
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
124 Каждый шаблон имеет собственное пространство имен, унаследованное от пространства имен фабрики элементов (которая в свою очередь наследует контекст документа).
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
125 В шаблоне могут определяться новые переменные, которые разделяются между блоками. Также доступны стандартные переменные
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
126
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
127 =over
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
128
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
129 =item * C<this> ссылка на объект элемента управления
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
130
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
131 =item * C<component> ссылка на текущий шаблон, устанавливается автоматически в методе C<Template::Context::process>.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
132
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
133 =item * C<template> ссылка на шаблон элемента управления, для совместимости с C<TT>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
134
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
135 =back
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
136
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
137 =head1 MEMBERS
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
138
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
139 =over
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
140
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
141 =item * C<[get]context>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
142
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
143 Контекст элемента управления, хранит пременные шаблона. Наследуется от контекста фабрики элементов управления, который
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
144 наследуется от контекста документа.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
145
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
146 =item * C<[get,set]template>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
147
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
148 C<Template::Document> Шаблон элемента управления.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
149
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
150 =item * C<AUTOLOAD>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
151
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
152 Для удобства работы с шаблоном, элементы управления предоставляю доступ к своим свойствам через метод C<AUTOLOAD>.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
153
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
154 =back
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
155
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157 C<lang ru>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
158
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
159 =cut