Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTControl.pm @ 191:78a18a2b6266
IMPL::Web::View improvements (unstable)
author | cin |
---|---|
date | Thu, 05 Apr 2012 17:51:51 +0400 |
parents | 08015e2803f1 |
children | a9faf883cdce |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTControl.pm Wed Apr 04 17:51:27 2012 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Thu Apr 05 17:51:51 2012 +0400 @@ -5,6 +5,7 @@ use IMPL::lang qw(:declare :constants); use Template::Context(); +use Scalar::Util qw(weaken); use parent qw( IMPL::DOM::Node @@ -34,12 +35,12 @@ $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); - if ( my $ctor = $template->blocks->{CTOR} ) { - $context->process($ctor, { this => $this } ); - $context->stash->set('this',undef); - } + $this->id($name . "-" . _GetNextId()) unless $this->id; - $this->id($name . "-" . _GetNextId()) unless $this->id; + weaken($this); # prevent cyclic references produces by the code below + + $context->stash->set('append', sub { $this->appendChild(@_); undef; } ); + $context->stash->set('select', sub { $this->selectNodes(@_) } ); } @@ -50,8 +51,19 @@ } ); +sub InitInstance { + my ($this,$args) = @_; + + $args ||= {}; + + if ( my $ctor = $this->template->blocks->{CTOR} ) { + $this->context->process($ctor, { %$args, this => $this } ); + $this->context->stash->set('this',undef); + } +} + sub renderBlock { - $_[0]->template->blocks->{RENDER}; + $_[0]->template->blocks->{RENDER} || $_[0]->template; } sub Render {