Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTFactory.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | a9faf883cdce |
children | 5c82eec23bb6 |
comparison
equal
deleted
inserted
replaced
193:8e8401c0aea4 | 194:4d0e1962161c |
---|---|
9 | 9 |
10 | 10 |
11 use parent qw(IMPL::Object::Factory); | 11 use parent qw(IMPL::Object::Factory); |
12 | 12 |
13 BEGIN { | 13 BEGIN { |
14 public property template => PROP_ALL; | 14 public property template => PROP_ALL; |
15 public property context => PROP_ALL; | 15 public property context => PROP_ALL; |
16 public property opts => PROP_ALL; | 16 public property opts => PROP_ALL; |
17 public property nodeProperties => PROP_ALL; | 17 public property nodeProperties => PROP_ALL; |
18 public property instances => PROP_GET | PROP_OWNERSET; | 18 public property instances => PROP_GET | PROP_OWNERSET; |
19 } | 19 } |
20 | 20 |
21 __PACKAGE__->PassThroughArgs; | 21 __PACKAGE__->PassThroughArgs; |
22 | 22 |
23 sub CTOR { | 23 sub CTOR { |
24 my ($this,$factory,$template,$context,$options,$nodeProps) = @_; | 24 my ($this,$factory,$template,$context,$options,$nodeProps) = @_; |
25 | 25 |
26 die IMPL::ArgumentException("A template is required") unless $template; | 26 die IMPL::ArgumentException("A template is required") unless $template; |
27 | 27 |
28 $options ||= {}; | 28 $options ||= {}; |
29 $context ||= new Template::Context($options); | 29 $context ||= new Template::Context($options); |
30 | 30 |
31 $this->template($template); | 31 $this->template($template); |
32 $this->context($context); | 32 $this->context($context); |
33 $this->opts($options); | 33 $this->opts($options); |
34 $this->nodeProperties($nodeProps || {}); | 34 $this->nodeProperties($nodeProps || {}); |
35 $this->instances(0); | 35 $this->instances(0); |
36 | |
37 my $doc = delete $nodeProps->{document}; | |
38 weaken($doc); | |
39 | |
40 $context->stash->set('require', sub { $doc->require(@_); } ); | |
41 } | 36 } |
42 | 37 |
43 our %CTOR = ( | 38 our %CTOR = ( |
44 'IMPL::Object::Factory' => sub { | 39 'IMPL::Object::Factory' => sub { |
45 $_[0] | 40 $_[0] |
46 } | 41 } |
47 ); | 42 ); |
48 | 43 |
49 sub MergeParameters { | 44 sub MergeParameters { |
50 my ($this,$name,$refProps) = @_; | 45 my ($this,$name,$refProps) = @_; |
51 | 46 |
52 my $opts = { %{ $this->opts } }; | 47 my $opts = { %{ $this->opts } }; |
53 $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; | 48 $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; |
54 | 49 |
55 my $ctx = new Template::Context($opts); | 50 my $ctx = new Template::Context($opts); |
56 | 51 |
57 return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); | 52 return ($name, $this->template, $ctx, hashMerge($this->nodeProperties,$refProps)); |
58 } | 53 } |
59 | 54 |
60 sub CreateObject { | 55 sub CreateObject { |
61 my $this = shift; | 56 my $this = shift; |
62 | 57 |
63 my $count = $this->instances; | 58 my $count = $this->instances; |
64 | 59 |
65 unless($count) { | 60 unless($count) { |
66 # нужно выполнить именно блок INIT шаблона при создании первого экземпляра | 61 # нужно выполнить именно блок INIT шаблона при создании первого экземпляра |
67 if (my $init = $this->template->blocks->{INIT}) { | 62 if (my $init = $this->template->blocks->{INIT}) { |
68 $this->context->process($init); | 63 $this->context->process($init); |
69 } | 64 } |
70 } | 65 } |
71 | 66 |
72 my $instance = $this->SUPER::CreateObject(@_); | 67 my $instance = $this->SUPER::CreateObject(@_); |
73 | 68 |
74 $instance->InitInstance(); | 69 $instance->InitInstance(); |
75 | 70 |
76 $count++; | 71 $count++; |
77 $this->instances($count); | 72 $this->instances($count); |
78 | 73 |
79 return $instance; | 74 return $instance; |
80 } | 75 } |
81 | 76 |
82 sub save { | 77 sub save { |
83 die new IMPL::NotImplementedException("This class doesn't support serialization"); | 78 die new IMPL::NotImplementedException("This class doesn't support serialization"); |
84 } | 79 } |
85 | 80 |
86 sub restore { | 81 sub restore { |
87 die new IMPL::NotImplementedException("This class doesn't support serialization"); | 82 die new IMPL::NotImplementedException("This class doesn't support serialization"); |
88 } | 83 } |
89 | 84 |
90 1; | 85 1; |
91 | 86 |
92 __END__ | 87 __END__ |
100 =head1 SYNOPSIS | 95 =head1 SYNOPSIS |
101 | 96 |
102 =begin code | 97 =begin code |
103 | 98 |
104 my $factory = new IMPL::Web::View::TTFactory( | 99 my $factory = new IMPL::Web::View::TTFactory( |
105 typeof IMPL::Web::View::TTControl, | 100 typeof IMPL::Web::View::TTControl, |
106 $doc, | 101 $doc, |
107 $context, | 102 $context, |
108 { | 103 { |
109 TRIM => 1 | 104 TRIM => 1 |
110 }, | 105 }, |
111 { | 106 { |
112 myprop => 'my value' | 107 myprop => 'my value' |
113 }, | 108 }, |
114 ); | 109 ); |
115 | 110 |
116 my $input1 = $factory->new('login', { class => "required" } ); | 111 my $input1 = $factory->new('login', { class => "required" } ); |
117 | 112 |
118 my $propval = $input->nodeProperty('myprop'); # 'my value' | 113 my $propval = $input->nodeProperty('myprop'); # 'my value' |
120 =end code | 115 =end code |
121 | 116 |
122 =begin text | 117 =begin text |
123 | 118 |
124 [% | 119 [% |
125 this.appendChild( | 120 this.appendChild( |
126 my.org.input.new('login', class = this.errors('login') ? "invalid" : "" ) | 121 my.org.input.new('login', class = this.errors('login') ? "invalid" : "" ) |
127 ); | 122 ); |
128 %] | 123 %] |
129 | 124 |
130 =end text | 125 =end text |
131 | 126 |
132 =head1 DESCRIPTION | 127 =head1 DESCRIPTION |