annotate Lib/IMPL/Web/View/TTControl.pm @ 352:675cd1829255

working on TTView: added control classes support
author cin
date Thu, 10 Oct 2013 19:51:19 +0400
parents f05634287ac7
children feeb3bc4a818
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
234
sergey
parents: 232
diff changeset
4 use IMPL::Const qw(:prop);
334
71221d79e6b4 removing web resources contracts
cin
parents: 314
diff changeset
5 use IMPL::lang qw(:hash :base);
234
sergey
parents: 232
diff changeset
6 use IMPL::declare {
sergey
parents: 232
diff changeset
7 require => {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
8 Exception => 'IMPL::Exception',
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
9 ArgException => '-IMPL::InvalidArgumentException'
234
sergey
parents: 232
diff changeset
10 },
sergey
parents: 232
diff changeset
11 base => [
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
12 'IMPL::Object' => undef
234
sergey
parents: 232
diff changeset
13 ],
sergey
parents: 232
diff changeset
14 props => [
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
15 context => PROP_RO,
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
16 template => PROP_RO,
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
17 _stash => PROP_RO,
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
18 id => {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
19 get => sub { shift->_stash->get('id') },
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
20 set => sub { shift->_stash->set('id',shift) }
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
21 }
234
sergey
parents: 232
diff changeset
22 ]
sergey
parents: 232
diff changeset
23 };
sergey
parents: 232
diff changeset
24
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
25
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
26 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
27 my $nextId = 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
28 sub _GetNextId {
299
sergey
parents: 296
diff changeset
29 return '_' . $nextId++;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 192
diff changeset
30 }
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
31 }
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
32
300
cin
parents: 299
diff changeset
33 our $AUTOLOAD_REGEX = qr/^[a-z]/;
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
34
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
35 sub CTOR {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
36 my ($this,$context,$template) = @_;
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
37
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
38 $this->context($context)
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
39 or die ArgException->new(context => 'A context is required');
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
40 $this->template($template)
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
41 or die ArgException->new(template => 'A template is required');
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
42
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
43 $this->_stash($context->stash);
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
44 }
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
45
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
46 sub Render {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
47 my ($this,$args) = @_;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
48 return $this->context->include($this->template,$args);
302
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
49 }
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
50
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
51 our $AUTOLOAD;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
52 sub AUTOLOAD {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
53 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
54
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
55 die Exception->new("Control doesn't have method '$prop'") unless $prop=~/$AUTOLOAD_REGEX/;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
56
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
57 no strict 'refs';
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
58
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
59 my $method = sub {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
60 if (@_ == 1) {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
61 return shift->_stash->get($prop);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
62 } elsif (@_ == 2) {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
63 return shift->_stash->set($prop,shift);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
64 } else {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
65 return shift->_stash->get([$prop,[@_]]);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
66 }
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
67 };
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
68
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
69 *{$AUTOLOAD} = $method;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
70
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
71 goto &$method;
314
cin
parents: 307
diff changeset
72 }
cin
parents: 307
diff changeset
73
342
1090c1dd7429 TTControl: added a helper method 'CreateControlFromTemlpate'
cin
parents: 334
diff changeset
74
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
75 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
76
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
77 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
78
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
83 C<IMPL::Web::View::TTControl> расширяет функциональность шаблонов
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
87 =begin code
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
88
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
89 package My::View::Menu;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
90 use IMPL::declare {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
91 base => [
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
92 'IMPL::Web::View::TTControl' => '@_'
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
93 ]
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
94 };
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
95
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
96 sub Render {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
97 my ($this,$args) = @_;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
98
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
99 $this->PrepareItems($args);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
100
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
101 return $this->next::method($args);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
102 }
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
103
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
104 sub PrepareItems
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
105
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
106 =end code
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
107
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
108 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
109
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
110
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
111 =cut