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