Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTLoader.pm @ 184:7525ea9a071a
IMPL::Web::View::TTLoader tests
author | sergey |
---|---|
date | Thu, 29 Mar 2012 01:54:20 +0400 |
parents | adc7669172c4 |
children | ae8072f2f2a3 |
line wrap: on
line diff
--- a/Lib/IMPL/Web/View/TTLoader.pm Wed Mar 28 17:28:51 2012 +0400 +++ b/Lib/IMPL/Web/View/TTLoader.pm Thu Mar 29 01:54:20 2012 +0400 @@ -26,12 +26,15 @@ sub CTOR { my ($this,$refOpts,%args) = @_; - $this->ext(delete $args{etx}); + $refOpts ||= {}; + + $this->ext(delete $args{ext}); $this->initializer(delete $args{initializer}); $this->options($refOpts); - $refOpts->{LOAD_TEMPLATES} = $this->provider(new Template::Provider($refOpts)); + # to aviod cyclic references we need to do a copy of $refOpts + $refOpts->{LOAD_TEMPLATES} = $this->provider(new Template::Provider( { %$refOpts } )); $this->context(new Template::Context($refOpts)); } @@ -43,7 +46,7 @@ $this->_init(); - my $opts = { $this->options }; + my $opts = { %{ $this->options } }; $opts->{STASH} = $this->context->stash->clone(); $opts->{LOAD_TEMPLATES} = $this->provider; @@ -62,9 +65,9 @@ my ($tt,$error) = $this->provider->fetch($name); - if ($error == STATUS_DECLINED) { + if (defined $error and $error == STATUS_DECLINED) { die new IMPL::KeyNotFoundException($name); - } elsif ($error == STATUS_ERROR) { + } elsif (defined $error and $error == STATUS_ERROR) { die new IMPL::Exception("Failed to load a template", $name, $tt); } @@ -74,7 +77,6 @@ sub _appendExt { my ($this,$name) = @_; - if (length $this->ext and substr( $name, -length($this->ext) ) eq $this->ext) { return $name; } else { @@ -86,13 +88,15 @@ my ($this) = @_; if (!$this->isInitialized) { - $this->isInitialized(1); - if ($this->initializer) { eval { $this->context->process($this->initializer); + }; + if (my $e = $@) { + die new IMPL::Exception("Failed to process an initializer", $this->initializer, $e); } } + $this->isInitialized(1); } }