Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTControl.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | a9faf883cdce |
children | 292226770180 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTControl.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Tue Apr 10 20:08:29 2012 +0400 @@ -8,86 +8,85 @@ use Scalar::Util qw(weaken); use parent qw( - IMPL::DOM::Node + IMPL::DOM::Node ); { - my $nextId = 1; - sub _GetNextId { - return $nextId++; - } + my $nextId = 1; + sub _GetNextId { + return $nextId++; + } } BEGIN { - public _dom property id => PROP_ALL; - - public property context => PROP_GET | PROP_OWNERSET; - public property template => PROP_ALL; + public _dom property id => PROP_ALL; + + public property context => PROP_GET | PROP_OWNERSET; + public property template => PROP_ALL; } sub CTOR { - my ($this,$name,$template,$context,$refProps) = @_; - - $name ||= "control"; - - $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); - $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); - - $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(@_); } ); - + my ($this,$name,$template,$context,$refProps) = @_; + + $name ||= "control"; + + $this->template( $template ) or die new IMPL::ArgumentException("A template is required"); + $this->context( $context ) or die new IMPL::ArgumentException("A context is required"); + + $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(@_); } ); + } our %CTOR = ( - 'IMPL::DOM::Node' => sub { - nodeName => $_[0], - %{ $_[3] || {} } - } + 'IMPL::DOM::Node' => sub { + nodeName => $_[0], + %{ $_[3] || {} } + } ); 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); - } + my ($this,$args) = @_; + + $args ||= {}; + + if ( my $ctor = $this->template->blocks->{CTOR} ) { + $this->context->include($ctor, { %$args, this => $this } ); + } } sub renderBlock { - $_[0]->template->blocks->{RENDER} || $_[0]->template; + $_[0]->template->blocks->{RENDER} || $_[0]->template; } sub Render { - my ($this,$args) = @_; - - $args = {} unless ref $args eq 'HASH'; - - if(my $body = $this->renderBlock ) { - return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } ); - } else { - return ""; - } + my ($this,$args) = @_; + + $args = {} unless ref $args eq 'HASH'; + + if(my $body = $this->renderBlock ) { + return $this->context->include( $body, { %$args, this => $this, template => $this->template, document => $this->document } ); + } else { + return ""; + } } sub AUTOLOAD { - our $AUTOLOAD; - - my $method = ($AUTOLOAD =~ m/(\w+)$/)[0]; - - return if $method eq 'DESTROY'; - - my $this = shift; - - $this->nodeProperty($method,@_); + our $AUTOLOAD; + + my $method = ($AUTOLOAD =~ m/(\w+)$/)[0]; + + return if $method eq 'DESTROY'; + + my $this = shift; + + $this->nodeProperty($method,@_); } 1;