annotate lib/IMPL/Config.pm @ 413:af8d359ee4cc ref20150831

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