Mercurial > pub > Impl
annotate Lib/IMPL/Web/View/TTView.pm @ 393:69a1f1508696
minor security refactoring
author | cin |
---|---|
date | Fri, 14 Feb 2014 16:41:12 +0400 |
parents | d5c8b955bf8d |
children | 6f2a494579cb |
rev | line source |
---|---|
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
1 package IMPL::Web::View::TTView; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
2 use strict; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
3 |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
4 use JSON; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
5 use IMPL::lang qw(hashMerge is); |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
6 use IMPL::Const qw(:prop); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
7 use IMPL::declare { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
8 require => { |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
9 Context => 'IMPL::Web::View::TTContext', |
371 | 10 Loader => 'IMPL::Code::Loader', |
11 Factory => 'IMPL::Web::View::ObjectFactory' | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
12 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
13 base => [ |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
14 'IMPL::Object' => undef, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
15 'IMPL::Object::Autofill' => '@_', |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
16 'IMPL::Object::Serializable' => undef |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
17 ], |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
18 props => [ |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
19 options => PROP_RW, |
353 | 20 viewBase => PROP_RW, |
21 layoutBase => PROP_RW, | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
22 layout => PROP_RW, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
23 tt_ext => PROP_RW, |
353 | 24 includes => PROP_RW | PROP_LIST, |
25 globals => PROP_RW | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
26 ] |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
27 }; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
28 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
29 sub CTOR { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
30 my ($this) = @_; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
31 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
32 $this->tt_ext('tt') unless defined $this->tt_ext; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
33 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
34 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
35 sub display { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
36 my ($this,$model,$template,$args) = @_; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
37 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
38 my $context = Context->new($this->options); |
353 | 39 my $layout = delete $args->{layout} || $this->layout; |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
40 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
41 return $context->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
42 sub { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
43 my $ctx = shift; |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
44 if ($layout) { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
45 return $ctx->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
46 sub { |
354 | 47 return shift->render( |
48 $layout, | |
49 hashMerge( | |
50 { | |
51 content => sub { | |
52 $ctx->invoke_environment( | |
53 sub { | |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
54 return shift->display_model($model,$template); |
354 | 55 }, |
56 { | |
57 base => $this->viewBase | |
58 } | |
59 ) | |
60 } | |
61 } | |
62 ) | |
63 ); # render | |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
64 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
65 { |
353 | 66 base => $this->layoutBase, |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
67 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
68 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
69 } else { |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
70 return $ctx->invoke_environment( |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
71 sub { |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
72 return shift->display_model($model,$template); |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
73 }, |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
74 { |
353 | 75 base => $this->viewBase |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
76 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
77 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
78 } |
353 | 79 },hashMerge( |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
80 $this->globals, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
81 hashMerge( |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
82 $args, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
83 { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
84 includes => scalar($this->includes), |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
85 tt_ext => $this->tt_ext, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
86 debug => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
87 warn @_; |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
88 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
89 is => sub { |
371 | 90 my ($obj,$class) = @_; |
91 if (is($class,Factory)) { | |
92 return is($obj,$class->factory); | |
93 } else { | |
94 return is($obj,$class); | |
95 } | |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
96 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
97 import => sub { |
371 | 98 return Factory->new(Loader->safe->Require(shift)); |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
99 }, |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
100 toJSON => sub { |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
101 return JSON->new()->utf8->pretty->encode(shift); |
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
102 } |
353 | 103 } |
359
833e663796c4
TTView: added view variable to pass rendering context between controls
sergey
parents:
354
diff
changeset
|
104 ) |
353 | 105 ) |
351
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
106 ); |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
107 } |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
108 |
cfd7570c2af2
working on TTView: created TTView class for rendering models
cin
parents:
diff
changeset
|
109 1; |