| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::MLite; # $Id: MLite.pm 32 2014-08-01 10:31:31Z minus $ |
|
2
|
1
|
|
|
1
|
|
48412
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
480
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
WWW::MLite - Lite Web Application Framework |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Version 1.05 |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use WWW::MLite; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 ABSTRACT |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
WWW::MLite - Lite Web Application Framework |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Lite Web Application Framework |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 METHODS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over 8 |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item B<new> |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $mlite = new WWW::MLite( ... args ... ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Returns object |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item B<show> |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$mlite->show( qw/foo bar baz/ ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Run project and send data to Apache |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B<register> |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$mlite->register( qw/Foo Bar Baz/ ); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Register all announced modules after creating object |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item B<get_recs> |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$mlite->get_recs( qw/foo bar baz/ ) |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Get metadata as one hash |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item B<get_rec> |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $data = $mlite->get_rec( "foo" ) |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Get data one key only |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item B<get_node, get> |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $name = $mlite->get( 'name' ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Getting node by name |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item B<set_node, set> |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$mlite->set( key => 'value' ); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Setting node by name |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item B<config, conf> |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $config = $mlite->config; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Getting config-node |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 HISTORY |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
See C<CHANGES> file |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L<CTK> |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 TO DO |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
See C<TODO> file |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 BUGS |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
* none noted |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
C<perl>, L<CTK> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Serz Minus (Lepenkov Sergey) L<http://www.serzik.com> E<lt>minus@mail333.comE<gt> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Copyright (C) 1998-2014 D&D Corporation. All Rights Reserved |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 LICENSE |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
|
109
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
|
110
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
111
|
|
|
|
|
|
|
(at your option) any later version. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
114
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
115
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
116
|
|
|
|
|
|
|
GNU General Public License for more details. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
See C<LICENSE> file |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|
|
122
|
1
|
|
|
1
|
|
10
|
use vars qw/ $VERSION /; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
108
|
|
|
123
|
|
|
|
|
|
|
$VERSION = '1.05'; |
|
124
|
|
|
|
|
|
|
|
|
125
|
1
|
|
|
1
|
|
57356
|
use Module::Load; |
|
|
1
|
|
|
|
|
2516
|
|
|
|
1
|
|
|
|
|
9
|
|
|
126
|
1
|
|
|
1
|
|
1719
|
use CTK::Util qw/ :API /; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use CTK::ConfGenUtil; |
|
128
|
|
|
|
|
|
|
use WWW::MLite::Config; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
use base qw/ |
|
131
|
|
|
|
|
|
|
WWW::MLite::Log |
|
132
|
|
|
|
|
|
|
WWW::MLite::Transaction |
|
133
|
|
|
|
|
|
|
/; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use constant { |
|
136
|
|
|
|
|
|
|
HANDLER => 'handler', |
|
137
|
|
|
|
|
|
|
}; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub new { |
|
140
|
|
|
|
|
|
|
my $class = shift; |
|
141
|
|
|
|
|
|
|
my %args = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Ïîäãðóæàåì ìîäóëü |
|
144
|
|
|
|
|
|
|
my $h_module = $args{module}; |
|
145
|
|
|
|
|
|
|
croak("The 'module' argument missing") unless $h_module; |
|
146
|
|
|
|
|
|
|
load $h_module; |
|
147
|
|
|
|
|
|
|
#croak("Module '$h_module' can't loaded"); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Ïðîâåðÿåì íàëè÷èå ãëàâíîãî õåíäëåðà |
|
150
|
|
|
|
|
|
|
my $h_handler = $args{handler} || HANDLER; |
|
151
|
|
|
|
|
|
|
croak("The 'handler' argument missing") unless $h_handler; |
|
152
|
|
|
|
|
|
|
my $handler = undef; |
|
153
|
|
|
|
|
|
|
#eval "\$handler = $h_module->can(\$h_handler)"; croak("Method '$h_handler' not exists. $@") if $@; |
|
154
|
|
|
|
|
|
|
croak("Method '$h_handler' not exists") unless $handler = $h_module->can($h_handler); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my $self = bless { |
|
160
|
|
|
|
|
|
|
name => $args{name} || 'noname', |
|
161
|
|
|
|
|
|
|
prefix => defined($args{prefix}) ? $args{prefix} : '', |
|
162
|
|
|
|
|
|
|
module => $h_module, |
|
163
|
|
|
|
|
|
|
handler => $handler, |
|
164
|
|
|
|
|
|
|
params => $args{params}, |
|
165
|
|
|
|
|
|
|
register => _to_arrayref($args{register}), |
|
166
|
|
|
|
|
|
|
meta => {}, |
|
167
|
|
|
|
|
|
|
inheritance => $args{inheritance} ? 1 : 0, # Âêëþ÷èòü íàñëåäîâàíèå çåðåãèñòðèðîâàííûõ ìîäóëåé |
|
168
|
|
|
|
|
|
|
config => new WWW::MLite::Config( # Êîíôèãóðàöèîííûå îïöèè |
|
169
|
|
|
|
|
|
|
file => $args{config_file}, |
|
170
|
|
|
|
|
|
|
dirs => $args{config_dirs}, |
|
171
|
|
|
|
|
|
|
), |
|
172
|
|
|
|
|
|
|
}, $class; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# Ðåãèñòðàöèÿ ìîäóëåé, åñëè îíè çàäàíû |
|
175
|
|
|
|
|
|
|
$self->register(); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
return $self; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
sub show { |
|
180
|
|
|
|
|
|
|
my $self = shift; |
|
181
|
|
|
|
|
|
|
croak("The method call not in the WWW::MLite context") unless ref($self) =~ /WWW\:\:MLite/; |
|
182
|
|
|
|
|
|
|
return $self->{handler}->($self, @_); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
sub register { |
|
185
|
|
|
|
|
|
|
my $self = shift; |
|
186
|
|
|
|
|
|
|
my @mdls = @_; |
|
187
|
|
|
|
|
|
|
@mdls = @{($self->{register})} unless @mdls; |
|
188
|
|
|
|
|
|
|
return 0 unless @mdls; |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
load $_ for @mdls; |
|
191
|
|
|
|
|
|
|
push @WWW::MLite::ISA, @mdls if $self->{inheritance}; |
|
192
|
|
|
|
|
|
|
my $meta = $self->{meta}; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
for (@mdls) { |
|
195
|
|
|
|
|
|
|
my @rec = (); |
|
196
|
|
|
|
|
|
|
if ($_->can("meta")) { |
|
197
|
|
|
|
|
|
|
@rec = $_->meta; |
|
198
|
|
|
|
|
|
|
} else { |
|
199
|
|
|
|
|
|
|
carp("Method 'meta' not exists in $_ package"); |
|
200
|
|
|
|
|
|
|
next; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
$meta->{$_} = { |
|
203
|
|
|
|
|
|
|
status => 'registered', |
|
204
|
|
|
|
|
|
|
actions => {@rec}, |
|
205
|
|
|
|
|
|
|
}; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
return 1; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
sub get_recs { |
|
210
|
|
|
|
|
|
|
# Get metadata as one hash where key = name of action, value = data of action |
|
211
|
|
|
|
|
|
|
my $self = shift; |
|
212
|
|
|
|
|
|
|
my @rq = @_; |
|
213
|
|
|
|
|
|
|
my $metas = hash($self->{meta}); |
|
214
|
|
|
|
|
|
|
my %recs = (); |
|
215
|
|
|
|
|
|
|
foreach my $k (keys %$metas) { |
|
216
|
|
|
|
|
|
|
my $actions = hash($metas, $k, "actions"); |
|
217
|
|
|
|
|
|
|
foreach my $a (keys %$actions) { |
|
218
|
|
|
|
|
|
|
if (@rq) { |
|
219
|
|
|
|
|
|
|
next unless grep {$a eq $_} @rq; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
$recs{$a} = hash($actions, $a); |
|
222
|
|
|
|
|
|
|
$recs{$a}{module} = $k; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
return {%recs} |
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
sub get_rec { |
|
228
|
|
|
|
|
|
|
# Get data by name of action |
|
229
|
|
|
|
|
|
|
my $self = shift; |
|
230
|
|
|
|
|
|
|
my $name = shift; |
|
231
|
|
|
|
|
|
|
return {} unless defined $name; |
|
232
|
|
|
|
|
|
|
return hash($self->get_recs($name), $name); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub get_node { |
|
236
|
|
|
|
|
|
|
# Ïðî÷èòàòü íîäó èç ãëîáàëüíîãî ìàññèâà |
|
237
|
|
|
|
|
|
|
my $self = shift; |
|
238
|
|
|
|
|
|
|
my $node = shift; |
|
239
|
|
|
|
|
|
|
return $self->{$node}; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
sub get { goto &get_node }; |
|
242
|
|
|
|
|
|
|
sub set_node { |
|
243
|
|
|
|
|
|
|
# Äîáàâèòü íîäó ê ãëîáàëüíîìó ìàññèâó |
|
244
|
|
|
|
|
|
|
my $self = shift; |
|
245
|
|
|
|
|
|
|
my $node = shift; |
|
246
|
|
|
|
|
|
|
my $data = shift; |
|
247
|
|
|
|
|
|
|
$self->{$node} = $data; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
sub set { goto &set_node }; |
|
250
|
|
|
|
|
|
|
sub config { return shift->{config}; }; |
|
251
|
|
|
|
|
|
|
sub conf { goto &config }; |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub _to_arrayref { |
|
254
|
|
|
|
|
|
|
my $p = shift; |
|
255
|
|
|
|
|
|
|
if ($p && ref($p) eq 'ARRAY') { |
|
256
|
|
|
|
|
|
|
return $p; |
|
257
|
|
|
|
|
|
|
} elsif (defined($p)) { |
|
258
|
|
|
|
|
|
|
return [$p]; |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
return []; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
263
|
|
|
|
|
|
|
# Ýòî ñâîåãî ðîäà èíòåðôåéñ êî âñåì ñâîéñòâàì ÷åðåç îáúåêòíóþ ìîäåëü |
|
264
|
|
|
|
|
|
|
# åñëè òàêîãî ñâîéñòâà íå îêàæèòñÿ, òî çíà÷èò ðóãàåìñÿ êàðïîì !! |
|
265
|
|
|
|
|
|
|
my $self = shift; |
|
266
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
267
|
|
|
|
|
|
|
my $AL = $AUTOLOAD; |
|
268
|
|
|
|
|
|
|
my $ss = undef; |
|
269
|
|
|
|
|
|
|
$ss = $1 if $AL=~/\:\:([^\:]+)$/; |
|
270
|
|
|
|
|
|
|
if ($ss && defined($self->{$ss})) { |
|
271
|
|
|
|
|
|
|
return $self->{$ss}; |
|
272
|
|
|
|
|
|
|
} else { |
|
273
|
|
|
|
|
|
|
carp("Can't find WWW::MLite node \"$ss\""); |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
return undef; |
|
276
|
|
|
|
|
|
|
} |
|
277
|
|
|
|
|
|
|
sub DESTROY { |
|
278
|
|
|
|
|
|
|
my $self = shift; |
|
279
|
|
|
|
|
|
|
#print STDERR "Object WWW::MLite destroyed\n"; |
|
280
|
|
|
|
|
|
|
return 1 unless $self && ref($self); |
|
281
|
|
|
|
|
|
|
#my $oo = $self->oracle; |
|
282
|
|
|
|
|
|
|
#my $mo = $self->mysql; |
|
283
|
|
|
|
|
|
|
#my $msoo = $self->multistore; |
|
284
|
|
|
|
|
|
|
#undef $oo; |
|
285
|
|
|
|
|
|
|
#undef $mo; |
|
286
|
|
|
|
|
|
|
#undef $msoo; |
|
287
|
|
|
|
|
|
|
return 1; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
1; |