comparison Lib/IMPL/Web/View/TTFactory.pm @ 192:a9faf883cdce

IMPL::Web::View refactoring
author cin
date Fri, 06 Apr 2012 16:22:38 +0400
parents 78a18a2b6266
children 4d0e1962161c
comparison
equal deleted inserted replaced
191:78a18a2b6266 192:a9faf883cdce
3 3
4 use Template::Context(); 4 use Template::Context();
5 5
6 use IMPL::lang qw(:hash :declare :constants); 6 use IMPL::lang qw(:hash :declare :constants);
7 use IMPL::Exception(); 7 use IMPL::Exception();
8 use Scalar::Util qw(weaken);
8 9
9 10
10 use parent qw(IMPL::Object::Factory); 11 use parent qw(IMPL::Object::Factory);
11 12
12 BEGIN { 13 BEGIN {
23 my ($this,$factory,$template,$context,$options,$nodeProps) = @_; 24 my ($this,$factory,$template,$context,$options,$nodeProps) = @_;
24 25
25 die IMPL::ArgumentException("A template is required") unless $template; 26 die IMPL::ArgumentException("A template is required") unless $template;
26 27
27 $options ||= {}; 28 $options ||= {};
29 $context ||= new Template::Context($options);
28 30
29 $this->template($template); 31 $this->template($template);
30 $this->context($context || new Template::Context($options)); 32 $this->context($context);
31 $this->opts($options || {}); 33 $this->opts($options);
32 $this->nodeProperties($nodeProps || {}); 34 $this->nodeProperties($nodeProps || {});
33 $this->instances(0); 35 $this->instances(0);
36
37 my $doc = delete $nodeProps->{document};
38 weaken($doc);
39
40 $context->stash->set('require', sub { $doc->require(@_); } );
34 } 41 }
35 42
36 our %CTOR = ( 43 our %CTOR = (
37 'IMPL::Object::Factory' => sub { 44 'IMPL::Object::Factory' => sub {
38 $_[0] 45 $_[0]