Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTDocument.pm @ 236:2904da230022
DOM refactoring
author | sergey |
---|---|
date | Mon, 15 Oct 2012 04:23:01 +0400 |
parents | 2530d1bb9638 |
children | b8c724f6de36 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTDocument.pm Fri Oct 12 02:08:51 2012 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Mon Oct 15 04:23:01 2012 +0400 @@ -1,28 +1,40 @@ package IMPL::Web::View::TTDocument; use strict; -use IMPL::lang qw(:declare ); -use IMPL::DOM::Property qw(_dom); -use IMPL::Web::View::TTFactory(); -use IMPL::Web::View::TTControl(); +use Scalar::Util qw(weaken); +use IMPL::Const qw(:prop); -use Scalar::Util qw(weaken); - - -use parent qw( - IMPL::DOM::Document - IMPL::Web::View::TTControl -); +use IMPL::declare { + require => { + TTFactory => 'IMPL::Web::View::TTFactory', + TTControl => 'IMPL::Web::View::TTControl', + Loader => 'IMPL::Code::Loader' + }, + base => [ + 'IMPL::Web::View::TTControl' => sub { + my ($template,$contextOpts) = @_; + 'document', + $_[0], # template + new Template::Context($_[1]) # context + }, + 'IMPL::DOM::Document' => sub { + nodeName => 'document' + } + ], + props => [ + layout => PROP_RW, + opts => PROP_RO, + loader => PROP_RW, + controls => PROP_RO, + + # store the stash separately to make require() method to work correctly + # even when a stash of the context is modified during the processing + stash => PROP_RO + ] +}; BEGIN { - public _dom property layout => PROP_ALL; - public property opts => PROP_GET | PROP_OWNERSET; - public property loader => PROP_ALL; - public property controls => PROP_GET | PROP_OWNERSET; - - # store the stash separately to make require() method to work correctly - # even when a stash of the context is modified during the processing - public property stash => PROP_GET | PROP_OWNERSET; + } sub CTOR { @@ -42,25 +54,13 @@ $this->templateVars('require', sub { my $doc = $self; die new IMPL::Exception("A document is destroyed or invalid") unless $doc; - $doc->require(@_); + $doc->RequireControl(@_); }); $this->templateVars('document', sub { $self } ); $this->InitInstance($vars); } -our %CTOR = ( - 'IMPL::Web::View::TTControl' => sub { - my ($template,$contextOpts) = @_; - 'document', - $_[0], # template - new Template::Context($_[1]) # context - }, - 'IMPL::DOM::Document' => sub { - nodeName => 'document' - } -); - sub templateVars { my $this = shift; my $name = shift; @@ -72,7 +72,7 @@ } } -sub require { +sub RequireControl { my ($this, $control, $nodeProps) = @_; $nodeProps ||= {}; @@ -98,6 +98,10 @@ $opts ); + if ($template->class) { + Loader->safe->Require($template->class); + } + my @parts = split(/\/+/,$control); $this->controls->{$control} = $factory; @@ -137,7 +141,6 @@ return $this->SUPER::Render(@_); } - 1; __END__ @@ -286,7 +289,7 @@ Получает или задает переменную для шаблона документа. Имя переменнной может быть составным, например C<'my.var.name'>, см. C<Template::Stash::set()>. -=item C<require($controlName)> +=item C<RequireControl($controlName)> Загружает фабрику элемента управления, если она уже была загружена, возвращает на нее ссылку. При загрузки фабрики для нее создается собственный контекст на основе параметров из свойства