annotate Lib/IMPL/Web/View/TTControl.pm @ 198:2ffe6f661605

Implemented IMPL::Web::Handler::RestController fixes in IMPL::Serialization completed IMPL::Web::Application::RestResource added IMPL::Web::Handler::JSONView added IMPL::Web::RestContract
author cin
date Fri, 20 Apr 2012 16:06:36 +0400
parents 4d0e1962161c
children 292226770180
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();
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 189
diff changeset
8 use Scalar::Util qw(weaken);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
9
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
10 use parent qw(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
11 IMPL::DOM::Node
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
12 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
13
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
14 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
15 my $nextId = 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
16 sub _GetNextId {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
17 return $nextId++;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
18 }
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
19 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
20
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
21
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22 BEGIN {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
23 public _dom property id => PROP_ALL;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
24
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
25 public property context => PROP_GET | PROP_OWNERSET;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
26 public property template => PROP_ALL;
181
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
30 sub CTOR {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
31 my ($this,$name,$template,$context,$refProps) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
32
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
33 $name ||= "control";
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
34
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
35 $this->template( $template ) or die new IMPL::ArgumentException("A template is required");
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
36 $this->context( $context ) or die new IMPL::ArgumentException("A context is required");
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
37
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
38 $this->id($name . "-" . _GetNextId()) unless $this->id;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
39
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
40 weaken($this); # prevent cyclic references produces by the code below
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
42 $context->stash->set('append', sub { $this->appendChild(@_); undef; } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
43 $context->stash->set('select', sub { $this->selectNodes(@_); } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
44
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
45 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
46
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
47 our %CTOR = (
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
48 'IMPL::DOM::Node' => sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
49 nodeName => $_[0],
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
50 %{ $_[3] || {} }
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
51 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
52 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
53
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 189
diff changeset
54 sub InitInstance {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
55 my ($this,$args) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
56
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
57 $args ||= {};
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
58
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
59 if ( my $ctor = $this->template->blocks->{CTOR} ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
60 $this->context->include($ctor, { %$args, this => $this } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
61 }
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 189
diff changeset
62 }
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 189
diff changeset
63
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
64 sub renderBlock {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
65 $_[0]->template->blocks->{RENDER} || $_[0]->template;
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
66 }
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
67
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
68 sub Render {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
69 my ($this,$args) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
70
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
71 $args = {} unless ref $args eq 'HASH';
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
72
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
73 if(my $body = $this->renderBlock ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
74 return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
75 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
76 return "";
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
77 }
185
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
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
80 sub AUTOLOAD {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
81 our $AUTOLOAD;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
82
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
83 my $method = ($AUTOLOAD =~ m/(\w+)$/)[0];
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
84
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
85 return if $method eq 'DESTROY';
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
86
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
87 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
88
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
89 $this->nodeProperty($method,@_);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
100 C<IMPL::Web::View::TTControl>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
101
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
102 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
103
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
104 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
105
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
106 =head2 BLOCKS
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
110 =head3 INIT
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
114 =head3 CTOR
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
116 данный блок выполняется каждый раз при создании нового экземпляра элемента управления, при этом переменная C<this>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
117 указывает на эземпляр элемента упарвления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
118
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119 =head3 RENDER
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
120
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
121 Данный блок выполняется при вызове метода C<Render()>, вывод данного блока и есть результат отображения элемента управления.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
122
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
123 =head2 TEMPLATE VARS
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
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
128 =over
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
129
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
130 =item * C<this> ссылка на объект элемента управления
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
131
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
132 =item * C<component> ссылка на текущий шаблон, устанавливается автоматически в методе C<Template::Context::process>.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
133
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
134 =item * C<template> ссылка на шаблон элемента управления, для совместимости с C<TT>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
135
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
136 =back
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
137
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
138 =head1 MEMBERS
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
139
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
140 =over
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
141
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
142 =item * C<[get]context>
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
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
147 =item * C<[get,set]template>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
148
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
149 C<Template::Document> Шаблон элемента управления.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
150
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
151 =item * C<AUTOLOAD>
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
152
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
153 Для удобства работы с шаблоном, элементы управления предоставляю доступ к своим свойствам через метод C<AUTOLOAD>.
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
154
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
155 =back
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
156
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
157
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
158 C<lang ru>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
159
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
160 =cut