annotate Lib/IMPL/Web/View/TTControl.pm @ 358:248f95c1762a

added simple XML Sax parser
author sergey
date Mon, 18 Nov 2013 01:25:35 +0400
parents 97131d500f16
children 833e663796c4
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 {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
23 my ($this,$context,$template) = @_;
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');
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
29 }
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
30
356
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
31 sub _PopulateMethods {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
32 my ($this,@methods) = @_;
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
33
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
34 $this->_stash->update({
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
35 map {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
36 my $name = $_;
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
37 $name,
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
38 sub {
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
39 $this->$name(@_);
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
40 }
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
41 } @methods
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
42 });
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
43 }
97131d500f16 TTView: added identifiers support
cin
parents: 353
diff changeset
44
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
45 sub _stash {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
46 $_[0]->context->stash;
238
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
47 }
b8c724f6de36 DOM model refactoring
sergey
parents: 236
diff changeset
48
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
49 sub Render {
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
50 my ($this,$args) = @_;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
51 return $this->context->include($this->template,$args);
302
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
52 }
673581380e79 Added templates provider functionality to controls
cin
parents: 301
diff changeset
53
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
54 our $AUTOLOAD;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
55 sub AUTOLOAD {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
56 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
57
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
58 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
59
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
60 no strict 'refs';
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
61
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
62 my $method = sub {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
63 my $that = shift;
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
64 if (@_ == 0) {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
65 return $that->_stash->get($prop);
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
66 } elsif (@_ == 1) {
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
67 return $that->_stash->set($prop,shift);
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
68 } else {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 352
diff changeset
69 return $that->_stash->get([$prop,[@_]]);
352
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 };
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 *{$AUTOLOAD} = $method;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
74
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
75 goto &$method;
314
cin
parents: 307
diff changeset
76 }
cin
parents: 307
diff changeset
77
342
1090c1dd7429 TTControl: added a helper method 'CreateControlFromTemlpate'
cin
parents: 334
diff changeset
78
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
79 1;
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
80
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
81 __END__
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
82
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
83 =pod
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
84
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
85 =head1 NAME
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 C<IMPL::Web::View::TTControl> расширяет функциональность шаблонов
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
88
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
89 =head1 SYNPOSIS
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
90
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
91 =begin code
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
92
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
93 package My::View::Menu;
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
94 use IMPL::declare {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
95 base => [
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
96 'IMPL::Web::View::TTControl' => '@_'
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
97 ]
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
98 };
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
99
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
100 sub Render {
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
101 my ($this,$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 $this->PrepareItems($args);
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 return $this->next::method($args);
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
106 }
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
107
352
675cd1829255 working on TTView: added control classes support
cin
parents: 346
diff changeset
108 sub PrepareItems
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 =end code
265
6b6d4b2275a1 improved documentation
cin
parents: 241
diff changeset
111
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
112 =head1 DESCRIPTION
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
113
187
927653d01f4f TTControl::AUTOLOAD now accesses nodeProperties
sergey
parents: 186
diff changeset
114
181
47dac58691ee New templating system, small fixes
sourcer
parents:
diff changeset
115 =cut