Mercurial > pub > Impl
annotate Lib/IMPL/Web/View/TTControl.pm @ 376:a54a2faf2f7e
added localizable string maps
author | cin |
---|---|
date | Mon, 13 Jan 2014 17:52:04 +0400 |
parents | 833e663796c4 |
children |
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 { |
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 | 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'); | |
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 | 36 } |
37 | |
356 | 38 sub _PopulateMethods { |
39 my ($this,@methods) = @_; | |
40 | |
41 $this->_stash->update({ | |
42 map { | |
43 my $name = $_; | |
44 $name, | |
45 sub { | |
46 $this->$name(@_); | |
47 } | |
48 } @methods | |
49 }); | |
50 } | |
51 | |
353 | 52 sub _stash { |
53 $_[0]->context->stash; | |
238 | 54 } |
55 | |
187 | 56 sub Render { |
352 | 57 my ($this,$args) = @_; |
58 return $this->context->include($this->template,$args); | |
302 | 59 } |
60 | |
352 | 61 our $AUTOLOAD; |
62 sub AUTOLOAD { | |
63 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/); | |
64 | |
353 | 65 die Exception->new("Method not found: $AUTOLOAD") unless $prop=~/$AUTOLOAD_REGEX/ and $_[0]; |
352 | 66 |
67 no strict 'refs'; | |
68 | |
69 my $method = sub { | |
353 | 70 my $that = shift; |
71 if (@_ == 0) { | |
72 return $that->_stash->get($prop); | |
73 } elsif (@_ == 1) { | |
74 return $that->_stash->set($prop,shift); | |
352 | 75 } else { |
353 | 76 return $that->_stash->get([$prop,[@_]]); |
352 | 77 } |
78 }; | |
79 | |
80 *{$AUTOLOAD} = $method; | |
81 | |
82 goto &$method; | |
314 | 83 } |
84 | |
342
1090c1dd7429
TTControl: added a helper method 'CreateControlFromTemlpate'
cin
parents:
334
diff
changeset
|
85 |
181 | 86 1; |
87 | |
88 __END__ | |
89 | |
90 =pod | |
91 | |
92 =head1 NAME | |
93 | |
352 | 94 C<IMPL::Web::View::TTControl> расширяет функциональность шаблонов |
181 | 95 |
96 =head1 SYNPOSIS | |
97 | |
352 | 98 =begin code |
99 | |
100 package My::View::Menu; | |
101 use IMPL::declare { | |
102 base => [ | |
103 'IMPL::Web::View::TTControl' => '@_' | |
104 ] | |
105 }; | |
265 | 106 |
352 | 107 sub Render { |
108 my ($this,$args) = @_; | |
109 | |
110 $this->PrepareItems($args); | |
111 | |
112 return $this->next::method($args); | |
113 } | |
265 | 114 |
352 | 115 sub PrepareItems |
116 | |
117 =end code | |
265 | 118 |
181 | 119 =head1 DESCRIPTION |
120 | |
187 | 121 |
181 | 122 =cut |