comparison Lib/IMPL/Web/View/TTDocument.pm @ 241:f48a1a9f4fa2

+Added ViewResult to allow implementation of the view environment. *TTDocuments now storing creation parameters *TTControls automatically propagating layout and title meta to their attributes +Added UnauthorizaedException web exception *minor fixes
author sergey
date Thu, 18 Oct 2012 04:49:55 +0400
parents b8c724f6de36
children 7c517134c42f
comparison
equal deleted inserted replaced
240:abc7c26bf615 241:f48a1a9f4fa2
1 package IMPL::Web::View::TTDocument; 1 package IMPL::Web::View::TTDocument;
2 use strict; 2 use strict;
3 3
4 use Scalar::Util qw(weaken); 4 use Scalar::Util qw(weaken);
5 use IMPL::Const qw(:prop); 5 use IMPL::Const qw(:prop);
6 use IMPL::lang qw(:hash);
6 7
7 use IMPL::declare { 8 use IMPL::declare {
8 require => { 9 require => {
9 TTFactory => 'IMPL::Web::View::TTFactory', 10 TTFactory => 'IMPL::Web::View::TTFactory',
10 TTControl => 'IMPL::Web::View::TTControl', 11 TTControl => 'IMPL::Web::View::TTControl',
21 props => [ 22 props => [
22 layout => PROP_RW, 23 layout => PROP_RW,
23 opts => PROP_RO, 24 opts => PROP_RO,
24 loader => PROP_RW, 25 loader => PROP_RW,
25 controls => PROP_RO, 26 controls => PROP_RO,
27 creationArgs => PROP_RO,
26 28
27 # store the stash separately to make require() method to work correctly 29 # store the stash separately to make require() method to work correctly
28 # even when a stash of the context is modified during the processing 30 # even when a stash of the context is modified during the processing
29 stash => PROP_RO 31 stash => PROP_RO
30 ] 32 ]
42 44
43 $this->layout( $template->layout ) unless $this->layout; 45 $this->layout( $template->layout ) unless $this->layout;
44 46
45 $this->opts($refOpts); 47 $this->opts($refOpts);
46 $this->stash($this->context->stash); 48 $this->stash($this->context->stash);
49 $this->creationArgs($vars);
47 50
48 my $self = $this; 51 my $self = $this;
49 weaken($self); 52 weaken($self);
50 53
51 $this->templateVars('require', sub { 54 $this->templateVars(require => sub {
52 my $doc = $self; 55 my $doc = $self;
53 die new IMPL::Exception("A document is destroyed or invalid") unless $doc; 56 die new IMPL::Exception("A document is destroyed or invalid") unless $doc;
54 $doc->RequireControl(@_); 57 $doc->RequireControl(@_);
55 }); 58 });
56 59
57 $this->templateVars('document', sub { $self } ); 60 $this->templateVars(context => $vars);
61
62 $this->templateVars(document => sub { $self } );
58 $this->InitInstance($vars); 63 $this->InitInstance($vars);
59 } 64 }
60 65
61 sub templateVars { 66 sub templateVars {
62 my $this = shift; 67 my $this = shift;
112 } 117 }
113 118
114 sub Render { 119 sub Render {
115 my ($this,$args) = @_; 120 my ($this,$args) = @_;
116 121
117 my $output; 122 $args ||= {};
123
124 my $newArgs = hashMerge($this->creationArgs, $args);
118 125
119 if ($this->layout) { 126 if ($this->layout) {
120 $output = $this->context->include( 127 return $this->context->include(
121 $this->loader->layout($this->layout), 128 $this->loader->layout($this->layout),
122 { 129 {
123 %{$args || {}}, 130 %{$newArgs},
124 content => sub { $this->RenderContent($args); }, 131 content => sub { $this->RenderContent($newArgs); },
125 this => $this, 132 this => $this,
126 template => $this->template 133 template => $this->template
127 } 134 }
128 ); 135 );
129 } else { 136 } else {
130 return $this->RenderContent($args); 137 return $this->RenderContent($newArgs);
131 } 138 }
132
133 return $output;
134 } 139 }
135 140
136 sub RenderContent { 141 sub RenderContent {
137 my $this = shift; 142 my $this = shift;
138 return $this->SUPER::Render(@_); 143 return $this->SUPER::Render(@_);