annotate Lib/IMPL/Web/View/TTControl.pm @ 185:ae8072f2f2a3

IMPL::Web::View::TTDocument tests, fixes
author cin
date Thu, 29 Mar 2012 18:22:15 +0400
parents 47dac58691ee
children 6c0fee769b0c
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 "";
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
50 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
51 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
52
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
53 sub AUTOLOAD {
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
54 our $AUTOLOAD;
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
55
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
56 my $method = ($AUTOLOAD =~ m/(\w+)$/)[0];
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
57
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
58 return if $method eq 'DESTROY';
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
59
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
60 my $res = $_[0]->template->$method();
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
61
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 181
diff changeset
62 return defined($res) ? $res : $_[0]->context->stash->get($method);
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
63
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
64 }
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
65
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
66 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
67
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
68 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
69
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
70 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
71
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
72 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
73
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
74 C<IMPL::Web::View::TTControl>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
78 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80 =head2 BLOCKS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81
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 =head3 INIT
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86 Данный блок шаблона управления выполняется один раз при создании первого экземпляра элемента управления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88 =head3 CTOR
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90 данный блок выполняется каждый раз при создании нового экземпляра элемента управления, при этом переменная C<this>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91 указывает на эземпляр элемента упарвления
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93 =head3 RENDER
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
94
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
98 C<lang ru>
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
99
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
100 =cut