Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTFactory.pm @ 300:bf3af33b9003
sync
| author | cin |
|---|---|
| date | Fri, 22 Mar 2013 01:05:11 +0400 |
| parents | 78f767765706 |
| children | aeeb57a12046 |
comparison
equal
deleted
inserted
replaced
| 299:bd79145657e5 | 300:bf3af33b9003 |
|---|---|
| 13 require => { | 13 require => { |
| 14 Loader => 'IMPL::Code::Loader' | 14 Loader => 'IMPL::Code::Loader' |
| 15 }, | 15 }, |
| 16 base => [ | 16 base => [ |
| 17 'IMPL::Object::Factory' => sub { | 17 'IMPL::Object::Factory' => sub { |
| 18 shift->class || 'IMPL::Web::View::TTControl' | 18 shift; |
| 19 } | 19 } |
| 20 ], | 20 ], |
| 21 props => [ | 21 props => [ |
| 22 template => PROP_RW, | 22 template => PROP_RW, |
| 23 context => PROP_RW, | 23 context => PROP_RW, |
| 24 instances => PROP_RW, | 24 instances => PROP_RW, |
| 25 base => PROP_RW, | 25 baseLocation => PROP_RW, |
| 26 require => PROP_RO | 26 require => PROP_RO |
| 27 ] | 27 ] |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 sub CTOR { | 30 sub CTOR { |
| 31 my ($this,$template,$context,$base,$require) = @_; | 31 my ($this,$class,$template,$context,$baseLocation,$require) = @_; |
| 32 | 32 |
| 33 die IMPL::ArgumentException("A template is required") unless $template; | 33 die IMPL::ArgumentException("A template is required") unless $template; |
| 34 | 34 |
| 35 Loader->safe->Require($this->factory) | 35 Loader->safe->Require($class) |
| 36 if $this->factory and not ref $this->factory; | 36 if $class and not ref $class; |
| 37 | 37 |
| 38 $context ||= new Template::Context(); | 38 $context ||= new Template::Context(); |
| 39 | 39 |
| 40 $this->template($template); | 40 $this->template($template); |
| 41 $this->context($context); | 41 $this->context($context); |
| 42 $this->base($base); | 42 $this->baseLocation($baseLocation); |
| 43 $this->instances(0); | 43 $this->instances(0); |
| 44 $this->require($require); | 44 $this->require($require); |
| 45 } | 45 } |
| 46 | 46 |
| 47 sub MergeParameters { | 47 sub MergeParameters { |
| 48 my ($this,$name,$refProps) = @_; | 48 my ($this,$refProps) = @_; |
| 49 | |
| 50 if (ref $name) { | |
| 51 $refProps = $name; | |
| 52 $name = (ref $refProps eq 'HASH' and ($refProps->{name} || $refProps->{id})) || '*anonymous*'; | |
| 53 } | |
| 54 | 49 |
| 55 $refProps->{factory} = $this; | 50 $refProps->{factory} = $this; |
| 56 | 51 |
| 57 my $base = $this->base; | 52 my $baseLocation = $this->baseLocation; |
| 58 | 53 |
| 59 $this->context->localise(); | 54 my $ctx = $this->CloneContext(); |
| 60 | 55 |
| 61 my $ctx = _clone_context($this->context); | |
| 62 | |
| 63 $this->context->delocalise(); | |
| 64 | |
| 65 my $stash = $ctx->stash; | |
| 66 my $require = $this->require; | 56 my $require = $this->require; |
| 67 | 57 |
| 68 | 58 $ctx->stash->update({ |
| 69 $stash->update({ | |
| 70 require => sub { | 59 require => sub { |
| 71 my ($module) = @_; | 60 my ($module) = @_; |
| 72 | 61 |
| 73 $module =~ s/^\.\//$base\//; | 62 $module =~ s/^\.\//$baseLocation\//; |
| 74 return $require->($module); | 63 return $require->($module); |
| 75 } | 64 } |
| 76 }); | 65 }); |
| 77 | 66 |
| 78 return ($name, $this->template, $ctx, $refProps); | 67 return ($this->template, $ctx, $refProps); |
| 79 } | 68 } |
| 80 | 69 |
| 81 sub CreateObject { | 70 sub CreateObject { |
| 82 my $this = shift; | 71 my $this = shift; |
| 83 | 72 |
| 100 $this->instances($count); | 89 $this->instances($count); |
| 101 | 90 |
| 102 return $instance; | 91 return $instance; |
| 103 } | 92 } |
| 104 | 93 |
| 105 sub _clone_context { | 94 sub CloneContext { |
| 106 my $args = { %{shift || {}} }; | 95 my ($this) = @_; |
| 96 | |
| 97 $this->context->localise(); | |
| 98 | |
| 99 my $args = { %{$this->context} }; | |
| 107 delete $args->{CONFIG}; | 100 delete $args->{CONFIG}; |
| 101 | |
| 102 $this->context->delocalise(); | |
| 108 | 103 |
| 109 return Template::Context->new($args); | 104 return Template::Context->new($args); |
| 110 } | 105 } |
| 111 | 106 |
| 112 sub save { | 107 sub save { |
