annotate Lib/IMPL/Web/View/TTView.pm @ 406:f23fcb19d3c1 ref20150831

implemented ServicesBag
author cin
date Mon, 31 Aug 2015 20:22:16 +0300
parents 16ff604298c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
10 Loader => 'IMPL::Code::Loader',
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
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
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
20 viewBase => PROP_RW,
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
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
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
24 includes => PROP_RW | PROP_LIST,
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
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);
399
cin
parents: 396
diff changeset
39 eval {
401
16ff604298c7 minor fixes
cin
parents: 399
diff changeset
40 $context->process('globals' . '.' . $this->tt_ext, $args);
399
cin
parents: 396
diff changeset
41 };
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
42 my $layout = delete $args->{layout} || $this->layout;
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
43
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
44 return $context->invoke_environment(
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
45 sub {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
46 my $ctx = shift;
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
47 if ($layout) {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
48 return $ctx->invoke_environment(
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
49 sub {
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
50 return shift->render(
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
51 $layout,
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
52 hashMerge(
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
53 {
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
54 content => sub {
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
55 $ctx->invoke_environment(
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
56 sub {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
57 return shift->display_model($model,$template);
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
58 },
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
59 {
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
60 base => $this->viewBase
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
61 }
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
62 )
396
sergey
parents: 371
diff changeset
63 },
sergey
parents: 371
diff changeset
64 model => $model
354
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
65 }
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
66 )
9330835535b9 fixed view double rendering
cin
parents: 353
diff changeset
67 ); # render
351
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 {
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
70 base => $this->layoutBase,
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
71 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
72 );
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
73 } else {
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
74 return $ctx->invoke_environment(
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
75 sub {
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
76 return shift->display_model($model,$template);
351
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
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
79 base => $this->viewBase
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
80 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
81 );
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
82 }
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
83 },hashMerge(
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
84 $this->globals,
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
85 hashMerge(
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
86 $args,
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
87 {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
88 includes => scalar($this->includes),
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
89 tt_ext => $this->tt_ext,
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
90 debug => sub {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
91 warn @_;
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
92 },
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
93 is => sub {
371
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
94 my ($obj,$class) = @_;
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
95 if (is($class,Factory)) {
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
96 return is($obj,$class->factory);
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
97 } else {
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
98 return is($obj,$class);
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
99 }
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
100 },
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
101 import => sub {
371
d5c8b955bf8d refactoring
cin
parents: 359
diff changeset
102 return Factory->new(Loader->safe->Require(shift));
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
103 },
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
104 toJSON => sub {
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
105 return JSON->new()->utf8->pretty->encode(shift);
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
106 }
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
107 }
359
833e663796c4 TTView: added view variable to pass rendering context between controls
sergey
parents: 354
diff changeset
108 )
353
feeb3bc4a818 corrected error handling while loading templates
cin
parents: 351
diff changeset
109 )
351
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
110 );
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
111 }
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
112
cfd7570c2af2 working on TTView: created TTView class for rendering models
cin
parents:
diff changeset
113 1;