comparison 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
comparison
equal deleted inserted replaced
266:89179bb8c388 267:bbc0da7ef90e
1 package IMPL::Web::View::TTFactory; 1 package IMPL::Web::View::TTFactory;
2 use strict; 2 use strict;
3 3
4 use Template::Context(); 4 use Template::Context();
5 5
6 use IMPL::lang qw(:hash :declare ); 6 use IMPL::lang qw(:hash);
7 use IMPL::Exception(); 7 use IMPL::Exception();
8 use Scalar::Util qw(weaken); 8 use Scalar::Util qw(weaken);
9 9
10 10
11 use parent qw(IMPL::Object::Factory); 11 use IMPL::Const qw(:prop);
12 12 use IMPL::declare {
13 BEGIN { 13 base => [
14 public property template => PROP_ALL; 14 'IMPL::Object::Factory' => '@_'
15 public property context => PROP_ALL; 15 ],
16 public property opts => PROP_ALL; 16 props => [
17 public property nodeProperties => PROP_ALL; 17 template => PROP_RW,
18 public property instances => PROP_GET | PROP_OWNERSET; 18 context => PROP_RW,
19 } 19 opts => PROP_RW,
20 20 instances => PROP_RW,
21 __PACKAGE__->PassThroughArgs; 21 base => PROP_RW
22 ]
23 };
22 24
23 sub CTOR { 25 sub CTOR {
24 my ($this,$factory,$template,$context,$options,$nodeProps) = @_; 26 my ($this,$factory,$template,$context,$options,$base) = @_;
25 27
26 die IMPL::ArgumentException("A template is required") unless $template; 28 die IMPL::ArgumentException("A template is required") unless $template;
27 29
28 $options ||= {}; 30 $options ||= {};
29 $context ||= new Template::Context($options); 31 $context ||= new Template::Context($options);
30 32
31 $this->template($template); 33 $this->template($template);
32 $this->context($context); 34 $this->context($context);
33 $this->opts($options); 35 $this->opts($options);
34 $this->nodeProperties($nodeProps || {}); 36 $this->base($base);
35 $this->instances(0); 37 $this->instances(0);
36 } 38 }
37 39
38 our %CTOR = ( 40 our %CTOR = (
39 'IMPL::Object::Factory' => sub { 41 'IMPL::Object::Factory' => sub {
45 my ($this,$name,$refProps) = @_; 47 my ($this,$name,$refProps) = @_;
46 48
47 my $opts = { %{ $this->opts } }; 49 my $opts = { %{ $this->opts } };
48 $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; 50 $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH};
49 51
52 my $base = $this->base;
53
50 my $ctx = new Template::Context($opts); 54 my $ctx = new Template::Context($opts);
51 55
52 return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); 56 my $stash = $ctx->stash;
57 weaken($stash);
58
59 $stash->update({
60 require => sub {
61 my ($module) = @_;
62
63 $module =~ s/^\.\//$base\//;
64 return $stash->get('document')->RequireControl($module);
65 }
66 });
67
68 return ($name, $this->template, $ctx, hashApply({ factory => $this },$refProps));
53 } 69 }
54 70
55 sub CreateObject { 71 sub CreateObject {
56 my $this = shift; 72 my $this = shift;
57 73