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