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