annotate Lib/IMPL/Web/View/TTControl.pm @ 395:212cc86e470b

Code cleanup DateTime locale support for HTTP requests
author sergey
date Thu, 20 Feb 2014 01:33:03 +0400
parents 833e663796c4
children
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,
356
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
16 template => PROP_RO
234
sergey
parents: 232
diff changeset
17 ]
sergey
parents: 232
diff changeset
18 };
sergey
parents: 232
diff changeset
19
300
cin
parents: 299
diff changeset
20 our $AUTOLOAD_REGEX = qr/^[a-z]/;
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
21
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
22 sub CTOR {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
23 my ($this,$context,$template,$args) = @_;
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 238
diff changeset
24
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
25 $this->context($context)
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
26 or die ArgException->new(context => 'A context is required');
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
27 $this->template($template)
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
28 or die ArgException->new(template => 'A template is required');
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
29
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
30 if (ref $args eq 'HASH') {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
31 while(my ($key, $value) = each %$args) {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
32 next if grep $_ eq $key, qw(context template);
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
33 $this->$key($value);
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
34 }
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 356
diff changeset
35 }
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
36 }
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
37
356
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
38 sub _PopulateMethods {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
39 my ($this,@methods) = @_;
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
40
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
41 $this->_stash->update({
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
42 map {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
43 my $name = $_;
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
44 $name,
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
45 sub {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
46 $this->$name(@_);
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
47 }
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
48 } @methods
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
49 });
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
50 }
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
51
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
52 sub _stash {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
53 $_[0]->context->stash;
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
54 }
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
55
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
56 sub Render {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
57 my ($this,$args) = @_;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
58 return $this->context->include($this->template,$args);
302
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
59 }
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
60
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
61 our $AUTOLOAD;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
62 sub AUTOLOAD {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
63 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
64
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
65 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
66
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
67 no strict 'refs';
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 my $method = sub {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
70 my $that = shift;
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
71 if (@_ == 0) {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
72 return $that->_stash->get($prop);
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
73 } elsif (@_ == 1) {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
74 return $that->_stash->set($prop,shift);
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
75 } else {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
76 return $that->_stash->get([$prop,[@_]]);
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
77 }
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
78 };
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
79
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
80 *{$AUTOLOAD} = $method;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
81
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
82 goto &$method;
314
cin
parents: 307
diff changeset
83 }
cin
parents: 307
diff changeset
84
342
1090c1dd7429 TTControl: added a helper method 'CreateControlFromTemlpate'
cin
parents: 334
diff changeset
85
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
86 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
87
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
91
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
92 =head1 NAME
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
93
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
94 C<IMPL::Web::View::TTControl> расширяет функциональность шаблонов
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
95
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
96 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
97
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
98 =begin code
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
99
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
100 package My::View::Menu;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
101 use IMPL::declare {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
102 base => [
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
103 'IMPL::Web::View::TTControl' => '@_'
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
104 ]
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
105 };
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
106
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
107 sub Render {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
108 my ($this,$args) = @_;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
109
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
110 $this->PrepareItems($args);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
111
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
112 return $this->next::method($args);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
113 }
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
114
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
115 sub PrepareItems
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
116
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
117 =end code
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
118
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
119 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
120
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
121
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
122 =cut