annotate Lib/IMPL/Config.pm @ 396:6f2a494579cb

sync
author sergey
date Mon, 24 Feb 2014 01:55:46 +0400
parents 212cc86e470b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
1 package IMPL::Config;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
3 use warnings;
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
4 use mro;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
5
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
6 use Carp qw(carp);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
7
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
8 use IMPL::lang qw(is);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
9 use IMPL::Exception;
278
4ddb27ff4a0b core refactoring
cin
parents: 263
diff changeset
10 use IMPL::Const qw(:access);
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
11 use IMPL::declare {
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
12 require => {
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
13 PropertyInfo => 'IMPL::Class::PropertyInfo',
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
14 XmlFormatter => 'IMPL::Serialization::XmlFormatter',
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
15 Serializer => '-IMPL::Serializer',
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
16 Activator => '-IMPL::Config::Activator',
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
17
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
18 Exception => 'IMPL::Exception',
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
19 IOException => '-IMPL::IOException'
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
20 },
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
21 base => [
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
22 'IMPL::Object::Accessor' => undef,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
23 'IMPL::Object::Serializable' => undef,
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
24 'IMPL::Object::Autofill' => '@_'
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
25 ]
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 205
diff changeset
26 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
27
170
b88b7fe60aa3 refactoring
sourcer
parents: 165
diff changeset
28 use File::Spec();
b88b7fe60aa3 refactoring
sourcer
parents: 165
diff changeset
29
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
30
170
b88b7fe60aa3 refactoring
sourcer
parents: 165
diff changeset
31 our $ConfigBase ||= '';
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
32 our $AppBase;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
33
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
34 sub LoadXMLFile {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
35 my ($self,$file) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
36
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
37 my $class = ref $self || $self;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
38
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
39 my $serializer = Serializer->new(
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
40 formatter => XmlFormatter->new(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
41 IdentOutput => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
42 SkipWhitespace => 1
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
43 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
44 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
45
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
46 open my $hFile,'<',$file or die IOException->new("Failed to open file",$file,$!);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
47
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
48 my $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
49 eval {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
50 $obj = $serializer->Deserialize($hFile);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
51 };
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
52
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
53 if ($@) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
54 my $e=$@;
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
55 die Exception->new("Can't load the configuration file",$file,$e);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
56 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
57 return $obj;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
58 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
59
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
60 sub SaveXMLFile {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
61 my ($this,$file) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
62
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
63 my $serializer = Serializer->new(
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
64 formatter => XmlFormatter->new(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
65 IdentOutput => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
66 SkipWhitespace => 1
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
67 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
68 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
69
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
70 open my $hFile,'>',$file or die IOException->new("Failed to open file",$file,$!);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
71
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
72 $serializer->Serialize($hFile, $this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
73 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
74
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
75 sub xml {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
76 my $this = shift;
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
77 my $serializer = Serializer->new(
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
78 formatter => XmlFormatter->new(
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
79 IdentOutput => 1,
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
80 SkipWhitespace => 1
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
81 )
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
82 );
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
83 my $str = '';
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
84 open my $hFile,'>',\$str or die IOException->new("Failed to open stream",$!);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
85
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
86 $serializer->Serialize($hFile, $this);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
87
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
88 undef $hFile;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
89
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
90 return $str;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
91 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
92
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
93 sub save {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
94 my ($this,$ctx) = @_;
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 60
diff changeset
95
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 60
diff changeset
96 my $val;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
97
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 60
diff changeset
98 $val = $this->rawGet($_) and $ctx->AddVar($_ => $val) foreach map $_->Name, $this->get_meta(
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
99 PropertyInfo,
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
100 sub {
278
4ddb27ff4a0b core refactoring
cin
parents: 263
diff changeset
101 $_->access == ACCESS_PUBLIC and
4ddb27ff4a0b core refactoring
cin
parents: 263
diff changeset
102 $_->setter;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
103 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
104 1);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
105 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
106
58
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
107 sub spawn {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
108 my ($this,$file) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
109 unless ($file) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
110 ($file = ref $this || $this) =~ s/:+/./g;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
111 $file .= ".xml";
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
112 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
113 return $this->LoadXMLFile( File::Spec->catfile($ConfigBase,$file) );
58
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
114 }
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
115
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
116 sub get {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
117 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
118
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
119 if (@_ == 1) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
120 my $obj = $this->SUPER::get(@_);
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
121 return is($obj,Activator) ? $obj->activate : $obj;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
122 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
123 my @objs = $this->SUPER::get(@_);
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
124 return map is($_,Activator) ? $_->activate : $_, @objs ;
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
125 }
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
126 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
127
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
128 sub rawGet {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
129 my $this = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
130 return $this->SUPER::get(@_);
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
131 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
132
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
133 sub Exists {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
134 $_[0]->SUPER::get($_[1]) ? 1 : 0;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
135 }
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
136
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
137 sub AppBase {
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
138 carp "obsolete";
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
139 shift;
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
140 File::Spec->catdir($AppBase,@_);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
141 }
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
142
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
143 sub AppDir {
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
144 shift;
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
145 File::Spec->catdir($AppBase,@_);
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
146 }
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
147
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
148 sub AppFile {
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
149 shift;
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
150 File::Spec->catfile($AppBase,@_);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
151 }
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
152
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
153 sub ConfigBase {
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
154 carp "obsolete";
205
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
155 shift;
891c04080658 IMPL::Web::View fixed template selection, release candidate
sergey
parents: 204
diff changeset
156 File::Spec->catdir($ConfigBase,@_);
204
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
157 }
d63f9a92d6d4 +IMPL::Config::Include - simple way to include external config
sergey
parents: 194
diff changeset
158
395
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
159 sub ConfigDir {
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
160 shift;
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
161 File::Spec->catdir($ConfigBase,@_);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
162 }
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
163
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
164 sub ConfigFile {
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
165 shift;
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
166 File::Spec->catfile($ConfigBase,@_);
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
167 }
212cc86e470b Code cleanup
sergey
parents: 278
diff changeset
168
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
169 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
170 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
171
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
172 =pod
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
173
73
wizard
parents: 63
diff changeset
174 =head1 NAME
wizard
parents: 63
diff changeset
175
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
176 C<IMPL::Config> - базовый класс для настраиваемого приложения.
73
wizard
parents: 63
diff changeset
177
wizard
parents: 63
diff changeset
178 =head1 SYNOPSIS
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
179
73
wizard
parents: 63
diff changeset
180 =begin code
wizard
parents: 63
diff changeset
181
wizard
parents: 63
diff changeset
182 # define application
wizard
parents: 63
diff changeset
183
wizard
parents: 63
diff changeset
184 package MyApp;
165
76515373dac0 Added Class::Template,
wizard
parents: 73
diff changeset
185 use parent qw(IMPL::Config);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
186
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
187 use IMPL::Class::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
188 use IMPL::Config::Class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
189
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
190 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
191 public property SimpleString => prop_all;
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
192 public property DataSource => prop_all;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
193 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
194
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
195 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
196 my $this = shift;
73
wizard
parents: 63
diff changeset
197
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
198 $this->DataSource(
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
199 new IMPL::Config::Activator(
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
200 factory => 'MyDataSource',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
201 parameters=>{
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
202 host => 'localhost',
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
203 user => 'dbuser'
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
204 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
205 )
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
206 ) unless $this->Exists('DataSource');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
207 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
208
73
wizard
parents: 63
diff changeset
209 # using application object
58
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
210
73
wizard
parents: 63
diff changeset
211 my $app = spawn MyApp('default.xml');
58
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
212
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
213 $app->Run();
a35b60b16a99 Configuration, late activation
wizard
parents: 49
diff changeset
214
73
wizard
parents: 63
diff changeset
215 =end code
wizard
parents: 63
diff changeset
216
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
217 Ниже приведен пример файла C<default.xml> содержащего настройки приложения
73
wizard
parents: 63
diff changeset
218
wizard
parents: 63
diff changeset
219 =begin code xml
wizard
parents: 63
diff changeset
220
wizard
parents: 63
diff changeset
221 <app type='MyApp'>
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
222 <SimpleString>The application</SimpleString>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
223 <DataSource type='IMPL::Config::Activator'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
224 <factory>MyDataSourceClass</factory>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
225 <parameters type='HASH'>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
226 <host>localhost</host>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
227 <user>dbuser</user>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
228 </parameters>
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
229 </DataSource>
73
wizard
parents: 63
diff changeset
230 </app>
wizard
parents: 63
diff changeset
231
wizard
parents: 63
diff changeset
232 =end code xml
wizard
parents: 63
diff changeset
233
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
234 =head1 DESCRIPTION
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
235
73
wizard
parents: 63
diff changeset
236 C<[Serializable]>
wizard
parents: 63
diff changeset
237
wizard
parents: 63
diff changeset
238 C<[Autofill]>
wizard
parents: 63
diff changeset
239
165
76515373dac0 Added Class::Template,
wizard
parents: 73
diff changeset
240 C<use parent IMPL::Object::Accessor>
73
wizard
parents: 63
diff changeset
241
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
242 Базовый класс для приложений. Использует подход, что приложение
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
243 является объектом, состояние которого предтавляет собой конфигурацию,
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
244 а методы - логику.
73
wizard
parents: 63
diff changeset
245
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
246 Данный класс реализует функционал десериализации (и сериализации) экземпляра
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
247 приложения из XML документа. Для этого используется механизм C<IMPL::Serialization>.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
248 При этом используются опции C<IMPL::Serialization::XmlFormatter> C<IdentOutput> и
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
249 C<SkipWhitespace> для записи документа в легко читаемом виде.
73
wizard
parents: 63
diff changeset
250
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
251 Поскольку в результате восстановления приложения восстанавливаются все элементы
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
252 из файла конфигурации, то это может потребовать значительных ресурсов для
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
253 создания частей, которые могут никогда не понадобиться. Например, не требуется инициализация
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
254 источника данных для передачи пользователю статических данных, сохраненных на диске.
73
wizard
parents: 63
diff changeset
255
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
256 Для решения этой проблемы используются специальные объекты C<IMPL::Config::Activator>.
73
wizard
parents: 63
diff changeset
257
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
258 Если у приложения описано свойство, в котором хранится C<IMPL::Config::Activator>, то
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
259 при первом обращении к такому свойству, будет создан объект вызовом метода
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
260 C<< IMPL::Config::Activator->activate() >> и возвращен как значение этого свойства.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
261 Таким образом реализуется прозрачная отложенная активация объектов, что позволяет
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
262 экономить ресурсы.
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
263
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
264 =head1 MEMBERS
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
265
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
266 =over
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
267
73
wizard
parents: 63
diff changeset
268 =item C<[static] LoadXMLFile($fileName) >
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
269
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
270 Создает из XML файла C<$fileName> экземпляр приложения
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
271
73
wizard
parents: 63
diff changeset
272 =item C<SaveXMLFile($fileName)>
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
273
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
274 Сохраняет приложение в файл C<$fileName>
73
wizard
parents: 63
diff changeset
275
wizard
parents: 63
diff changeset
276 =item C<[get] xml >
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
277
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
278 Сохраняет конфигурацию приложения в XML строку.
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
279
73
wizard
parents: 63
diff changeset
280 =item C<[static,operator] spawn($file)>
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
281
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
282 Синоним для C<LoadXMLFile>, предполагается использование как оператора.
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
283
73
wizard
parents: 63
diff changeset
284 =item C<rawGet($propname,...)>
wizard
parents: 63
diff changeset
285
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
286 Метод для получения значений свойств приложения. Данный метод позволяет избежать
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 179
diff changeset
287 использование активации объектов через C<IMPL::Config::Activator>.
60
b0c068da93ac Lazy activation for the configuration objects (final concept)
wizard
parents: 58
diff changeset
288
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
289 =back
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
290
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 47
diff changeset
291 =cut