annotate Lib/IMPL/Web/View/TTControl.pm @ 184:7525ea9a071a

IMPL::Web::View::TTLoader tests
author sergey
date Thu, 29 Mar 2012 01:54:20 +0400
parents 47dac58691ee
children ae8072f2f2a3
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
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
13 my $nextId = 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
14
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
15
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
16 BEGIN {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
17 public _dom property id => PROP_ALL;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
18
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
19 public property context => PROP_GET | PROP_OWNERSET;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
20 public property template => PROP_ALL;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
21 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
23
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
24 sub CTOR {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
25 my ($this,$name,$template,$context,$refProps) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
26
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
27 $this->template( $template ) or die new IMPL::ArgumentException("A template is required");
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
28 $this->context( $context ) or die new IMPL::ArgumentException("A context is required");
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
29
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
30 if ( my $ctor = $template->blocks->{CTOR} ) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
31 $context->process($ctor, { this => $this } );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
32 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
33
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
34 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
35
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
36 our %CTOR = (
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
37 'IMPL::DOM::Node' => sub {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
38 nodeName => $_[0],
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
39 %{ $_[3] || {} }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
40 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
41 );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
42
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
43 sub Render {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
44 my ($this) = @_;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
45
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
46 if(my $body = $this->template->blocks->{RENDER} ) {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
47 return $this->context->process( $body, { this => $this } );
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
48 } else {
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
49 return "";
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
50 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
51
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
52 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
53
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
54 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
55
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
56 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
57
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
58 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
59
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
60 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
61
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
62 C<IMPL::Web::View::TTControl>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
63
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
64 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
65
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
66 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
67
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
68 =head2 BLOCKS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
69
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
70 При загрузке шаблона, создается фабрика, с собственным контекстом в которой выполняется шаблон элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
71
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
72 =head3 INIT
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
73
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
74 Данный блок шаблона управления выполняется один раз при создании первого экземпляра элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76 =head3 CTOR
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
78 данный блок выполняется каждый раз при создании нового экземпляра элемента управления, при этом переменная C<this>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 указывает на эземпляр элемента упарвления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 =head3 RENDER
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
83
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86 C<lang ru>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88 =cut