annotate Lib/IMPL/Config.pm @ 236:2904da230022

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