Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTFactory.pm @ 267:bbc0da7ef90e
*IMPL::Web::View refactoring
author | cin |
---|---|
date | Thu, 17 Jan 2013 02:39:44 +0400 |
parents | 5c82eec23bb6 |
children | c6d0f889ef87 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTFactory.pm Mon Jan 14 03:10:06 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Thu Jan 17 02:39:44 2013 +0400 @@ -3,25 +3,27 @@ use Template::Context(); -use IMPL::lang qw(:hash :declare ); +use IMPL::lang qw(:hash); use IMPL::Exception(); use Scalar::Util qw(weaken); -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; -} - -__PACKAGE__->PassThroughArgs; +use IMPL::Const qw(:prop); +use IMPL::declare { + base => [ + 'IMPL::Object::Factory' => '@_' + ], + props => [ + template => PROP_RW, + context => PROP_RW, + opts => PROP_RW, + instances => PROP_RW, + base => PROP_RW + ] +}; sub CTOR { - my ($this,$factory,$template,$context,$options,$nodeProps) = @_; + my ($this,$factory,$template,$context,$options,$base) = @_; die IMPL::ArgumentException("A template is required") unless $template; @@ -31,7 +33,7 @@ $this->template($template); $this->context($context); $this->opts($options); - $this->nodeProperties($nodeProps || {}); + $this->base($base); $this->instances(0); } @@ -47,9 +49,23 @@ my $opts = { %{ $this->opts } }; $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; + my $base = $this->base; + my $ctx = new Template::Context($opts); - return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); + my $stash = $ctx->stash; + weaken($stash); + + $stash->update({ + require => sub { + my ($module) = @_; + + $module =~ s/^\.\//$base\//; + return $stash->get('document')->RequireControl($module); + } + }); + + return ($name, $this->template, $ctx, hashApply({ factory => $this },$refProps)); } sub CreateObject {