Mercurial > pub > Impl
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 352:675cd1829255 | 353:feeb3bc4a818 | 
|---|---|
| 12 'IMPL::Object' => undef | 12 'IMPL::Object' => undef | 
| 13 ], | 13 ], | 
| 14 props => [ | 14 props => [ | 
| 15 context => PROP_RO, | 15 context => PROP_RO, | 
| 16 template => PROP_RO, | 16 template => PROP_RO, | 
| 17 _stash => PROP_RO, | |
| 18 id => { | 17 id => { | 
| 19 get => sub { shift->_stash->get('id') }, | 18 get => sub { shift->_stash->get('id') }, | 
| 20 set => sub { shift->_stash->set('id',shift) } | 19 set => sub { shift->_stash->set('id',shift) } | 
| 21 } | 20 } | 
| 22 ] | 21 ] | 
| 37 | 36 | 
| 38 $this->context($context) | 37 $this->context($context) | 
| 39 or die ArgException->new(context => 'A context is required'); | 38 or die ArgException->new(context => 'A context is required'); | 
| 40 $this->template($template) | 39 $this->template($template) | 
| 41 or die ArgException->new(template => 'A template is required'); | 40 or die ArgException->new(template => 'A template is required'); | 
| 42 | 41 } | 
| 43 $this->_stash($context->stash); | 42 | 
| 43 sub _stash { | |
| 44 $_[0]->context->stash; | |
| 44 } | 45 } | 
| 45 | 46 | 
| 46 sub Render { | 47 sub Render { | 
| 47 my ($this,$args) = @_; | 48 my ($this,$args) = @_; | 
| 48 return $this->context->include($this->template,$args); | 49 return $this->context->include($this->template,$args); | 
| 50 | 51 | 
| 51 our $AUTOLOAD; | 52 our $AUTOLOAD; | 
| 52 sub AUTOLOAD { | 53 sub AUTOLOAD { | 
| 53 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/); | 54 my ($prop) = ($AUTOLOAD =~ m/(\w+)$/); | 
| 54 | 55 | 
| 55 die Exception->new("Control doesn't have method '$prop'") unless $prop=~/$AUTOLOAD_REGEX/; | 56 die Exception->new("Method not found: $AUTOLOAD") unless $prop=~/$AUTOLOAD_REGEX/ and $_[0]; | 
| 56 | 57 | 
| 57 no strict 'refs'; | 58 no strict 'refs'; | 
| 58 | 59 | 
| 59 my $method = sub { | 60 my $method = sub { | 
| 60 if (@_ == 1) { | 61 my $that = shift; | 
| 61 return shift->_stash->get($prop); | 62 if (@_ == 0) { | 
| 62 } elsif (@_ == 2) { | 63 return $that->_stash->get($prop); | 
| 63 return shift->_stash->set($prop,shift); | 64 } elsif (@_ == 1) { | 
| 65 return $that->_stash->set($prop,shift); | |
| 64 } else { | 66 } else { | 
| 65 return shift->_stash->get([$prop,[@_]]); | 67 return $that->_stash->get([$prop,[@_]]); | 
| 66 } | 68 } | 
| 67 }; | 69 }; | 
| 68 | 70 | 
| 69 *{$AUTOLOAD} = $method; | 71 *{$AUTOLOAD} = $method; | 
| 70 | 72 | 
