Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTFactory.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 | 5c82eec23bb6 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTFactory.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Tue Apr 10 20:08:29 2012 +0400 @@ -11,80 +11,75 @@ use parent qw(IMPL::Object::Factory); BEGIN { - public property template => PROP_ALL; - public property context => PROP_ALL; - public property opts => PROP_ALL; - public property nodeProperties => PROP_ALL; - public property instances => PROP_GET | PROP_OWNERSET; + public property template => PROP_ALL; + public property context => PROP_ALL; + public property opts => PROP_ALL; + public property nodeProperties => PROP_ALL; + public property instances => PROP_GET | PROP_OWNERSET; } __PACKAGE__->PassThroughArgs; sub CTOR { - my ($this,$factory,$template,$context,$options,$nodeProps) = @_; - - die IMPL::ArgumentException("A template is required") unless $template; - - $options ||= {}; - $context ||= new Template::Context($options); - - $this->template($template); - $this->context($context); - $this->opts($options); - $this->nodeProperties($nodeProps || {}); - $this->instances(0); - - my $doc = delete $nodeProps->{document}; - weaken($doc); - - $context->stash->set('require', sub { $doc->require(@_); } ); + my ($this,$factory,$template,$context,$options,$nodeProps) = @_; + + die IMPL::ArgumentException("A template is required") unless $template; + + $options ||= {}; + $context ||= new Template::Context($options); + + $this->template($template); + $this->context($context); + $this->opts($options); + $this->nodeProperties($nodeProps || {}); + $this->instances(0); } our %CTOR = ( - 'IMPL::Object::Factory' => sub { - $_[0] - } + 'IMPL::Object::Factory' => sub { + $_[0] + } ); sub MergeParameters { - my ($this,$name,$refProps) = @_; - - my $opts = { %{ $this->opts } }; - $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; - - my $ctx = new Template::Context($opts); - - return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); + my ($this,$name,$refProps) = @_; + + my $opts = { %{ $this->opts } }; + $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; + + my $ctx = new Template::Context($opts); + + return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); } sub CreateObject { - my $this = shift; - - my $count = $this->instances; - - unless($count) { - # нужно выполнить именно блок INIT шаблона при создании первого экземпляра - if (my $init = $this->template->blocks->{INIT}) { - $this->context->process($init); - } - } - - my $instance = $this->SUPER::CreateObject(@_); - - $instance->InitInstance(); - - $count++; - $this->instances($count); - - return $instance; + my $this = shift; + + my $count = $this->instances; + + unless($count) { + # нужно выполнить именно блок INIT шаблона при создании первого экземпляра + if (my $init = $this->template->blocks->{INIT}) { + $this->context->process($init); + } + } + + my $instance = $this->SUPER::CreateObject(@_); + + $instance->InitInstance(); + + $count++; + $this->instances($count); + + return $instance; } sub save { - die new IMPL::NotImplementedException("This class doesn't support serialization"); + die new IMPL::NotImplementedException("This class doesn't support serialization"); } sub restore { - die new IMPL::NotImplementedException("This class doesn't support serialization"); + die new IMPL::NotImplementedException("This class doesn't support serialization"); } 1; @@ -102,15 +97,15 @@ =begin code my $factory = new IMPL::Web::View::TTFactory( - typeof IMPL::Web::View::TTControl, - $doc, - $context, - { - TRIM => 1 - }, - { - myprop => 'my value' - }, + typeof IMPL::Web::View::TTControl, + $doc, + $context, + { + TRIM => 1 + }, + { + myprop => 'my value' + }, ); my $input1 = $factory->new('login', { class => "required" } ); @@ -122,9 +117,9 @@ =begin text [% - this.appendChild( - my.org.input.new('login', class = this.errors('login') ? "invalid" : "" ) - ); + this.appendChild( + my.org.input.new('login', class = this.errors('login') ? "invalid" : "" ) + ); %] =end text