annotate Lib/IMPL/Web/View/TTControl.pm @ 353:feeb3bc4a818

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