line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Che; |
2
|
1
|
|
|
1
|
|
68885
|
use Mojo::Base::Che; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
6
|
use Mojo::Base 'Mojolicious'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
640
|
use Mojo::Log::Che; |
|
1
|
|
|
|
|
36
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
91
|
use Mojo::Loader qw(load_class); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2802
|
|
6
|
|
|
|
|
|
|
#~ use Mojo::Util qw(url_unescape); |
7
|
|
|
|
|
|
|
#~ use Scalar::Util 'weaken'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
0
|
|
|
0
|
1
|
|
my ($class, %args) = @_; |
11
|
0
|
|
0
|
|
|
|
my $config = delete($args{config}) || 'Config.pm'; |
12
|
0
|
|
|
|
|
|
my $app = $class->SUPER::new(%args); |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
$app->plugin(Config =>{file => $config}); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#~ return $app # остановка или двойной перезапуск kill -USR2 |
17
|
|
|
|
|
|
|
#~ if $ENV{HYPNOTOAD_PID} || $ENV{HYPNOTOAD_STOP}; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $conf = $app->config; |
20
|
0
|
|
0
|
|
|
|
$conf->{mojo} ||= {}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
0
|
|
|
|
my $defaults = $conf->{'mojo_defaults'} || $conf->{'mojo'}{'defaults'} || $conf->{'mojo.defaults'}; |
23
|
0
|
0
|
|
|
|
|
$app->defaults($defaults) |
24
|
|
|
|
|
|
|
if $defaults; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
0
|
|
|
|
my $secret = $conf->{'mojo_secret'} || $conf->{'mojo_secrets'} || $conf->{'mojo'}{'secret'} || $conf->{'mojo'}{'secrets'} || $conf->{'mojo.secret'} || $conf->{'mojo.secrets'} || $conf->{'шифры'} || [rand]; |
27
|
0
|
|
|
|
|
|
$app->secrets($secret); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
0
|
|
|
|
my $mode = $conf->{'mojo_mode'} || $conf->{'mojo'}{'mode'} || $conf->{'mojo.mode'}; |
30
|
0
|
0
|
|
|
|
|
$app->mode($mode) # Файл лога уже не переключишь |
31
|
|
|
|
|
|
|
if $mode; |
32
|
|
|
|
|
|
|
#~ $app->log->level( $conf->{'mojo_log_level'} || $conf->{'mojo'}{'log_level'} || 'debug'); |
33
|
0
|
|
0
|
|
|
|
my $log = $conf->{'mojo_log'} || $conf->{'mojo.log'} || $conf->{'mojo'}{'log'}; |
34
|
0
|
0
|
|
|
|
|
$app->log(Mojo::Log::Che->new(%$log)) |
35
|
|
|
|
|
|
|
if $log; |
36
|
|
|
|
|
|
|
#~ warn "Mode: ", $app->mode, "; log level: ", $app->log->level; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $home = $app->home; |
39
|
0
|
|
0
|
|
|
|
my $statics = $conf->{'mojo_static_paths'} || $conf->{'mojo.static.paths'} || $conf->{'mojo'}{'static'}{'paths'} || []; |
40
|
|
|
|
|
|
|
#~ push @{$app->static->paths}, @{$paths} if $paths; |
41
|
0
|
|
|
|
|
|
push @{$app->static->paths}, $home->rel_file($_) for @$statics; |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
0
|
|
|
|
my $templates_paths = $conf->{'mojo_renderer_paths'} || $conf->{'mojo.renderer.paths'} || $conf->{'mojo'}{'renderer'}{'paths'} || []; |
44
|
0
|
|
|
|
|
|
push @{$app->renderer->paths}, $home->rel_dir($_) for @$templates_paths; |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
0
|
|
0
|
|
|
|
my $renderer_classes = $conf->{'mojo_renderer_classes'} || $conf->{'mojo.renderer.classes'} || $conf->{'mojo'}{'renderer'}{'classes'} || []; |
47
|
0
|
|
|
|
|
|
push @{$app->renderer->classes}, $_ for grep ! load_class($_), @$renderer_classes; |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$app->сессия(); |
50
|
0
|
|
|
|
|
|
$app->хазы(); |
51
|
0
|
|
|
|
|
|
$app->плугины(); |
52
|
0
|
|
|
|
|
|
$app->хуки(); |
53
|
0
|
|
|
|
|
|
$app->спейсы(); |
54
|
0
|
|
|
|
|
|
$app->маршруты(); |
55
|
0
|
|
|
|
|
|
$app->задачи(); |
56
|
0
|
|
|
|
|
|
$app->типы(); |
57
|
|
|
|
|
|
|
#~ $app->minion_worker(); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $app; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub хазы { # Хазы из конфига |
64
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
65
|
0
|
|
|
|
|
|
my $conf = $app->config; |
66
|
0
|
|
0
|
|
|
|
my $h = $conf->{'mojo_has'} || $conf->{'mojo.has'} || $conf->{'mojo'}{'has'} || $conf->{'хазы'}; |
67
|
|
|
|
|
|
|
map { |
68
|
0
|
|
|
|
|
|
$app->log->debug("Make the app->has('$_')"); |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
has $_ => $h->{$_}; |
70
|
|
|
|
|
|
|
} keys %$h; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#~ sub плугины {# Плугины из конфига |
74
|
|
|
|
|
|
|
has плугины => sub { |
75
|
|
|
|
|
|
|
my $app = shift; |
76
|
|
|
|
|
|
|
my $conf = $app->config; |
77
|
|
|
|
|
|
|
my $плугины = {}; |
78
|
|
|
|
|
|
|
my $plugins = $conf->{'mojo_plugins'} || $conf->{'mojo.plugins'} || $conf->{'mojo'}{'plugins'} || $conf->{'плугины'} |
79
|
|
|
|
|
|
|
|| return; |
80
|
|
|
|
|
|
|
map { |
81
|
|
|
|
|
|
|
push @{ $плугины->{$_->[0]} ||= [] }, [ref $_->[1] eq 'CODE' ? $app->plugin($_->[0] => $app->${ \$_->[1] }) : $app->plugin(@$_)]; |
82
|
|
|
|
|
|
|
$app->log->debug("Enable plugin [$_->[0]]"); |
83
|
|
|
|
|
|
|
} @$plugins; |
84
|
|
|
|
|
|
|
return $плугины; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has dbh => sub {#~ sub базы {# обрабатывает dbh конфига |
88
|
|
|
|
|
|
|
my $app = shift; |
89
|
|
|
|
|
|
|
my $conf = $app->config; |
90
|
|
|
|
|
|
|
my $c_dbh = $conf->{dbh} || $conf->{'базы'}; |
91
|
|
|
|
|
|
|
return unless $c_dbh && ref($c_dbh) eq 'HASH' && keys %$c_dbh; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $dbh = {}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $req_dbi; |
96
|
|
|
|
|
|
|
while (my ($db, $opt) = each %$c_dbh) { |
97
|
|
|
|
|
|
|
if ($opt->{dbh}) {# && ref $opt eq 'DBI::db' |
98
|
|
|
|
|
|
|
$dbh->{$db} ||= $opt->{dbh}; |
99
|
|
|
|
|
|
|
} else { |
100
|
|
|
|
|
|
|
++$req_dbi |
101
|
|
|
|
|
|
|
and require DBI |
102
|
|
|
|
|
|
|
unless $req_dbi; |
103
|
|
|
|
|
|
|
$dbh->{$db} ||= DBI->connect(@{$opt->{connect}}); |
104
|
|
|
|
|
|
|
$app->log->debug("Соединился с базой $opt->{connect}[0] app->dbh->{'$db'}"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
map { |
108
|
|
|
|
|
|
|
$dbh->{$db}->do($_); |
109
|
|
|
|
|
|
|
} @{$opt->{do}} if $opt->{do}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
return $dbh; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#~ has sth => sub {#~ sub запросы {# обрабатывает sth конфига |
118
|
|
|
|
|
|
|
#~ my $app = shift; |
119
|
|
|
|
|
|
|
#~ my $dbh = eval { $app->dbh } |
120
|
|
|
|
|
|
|
#~ or return; |
121
|
|
|
|
|
|
|
#~ my $conf = $app->config; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#~ my $c_dbh = $conf->{dbh} || $conf->{'базы'}; |
124
|
|
|
|
|
|
|
#~ my $c_sth = $conf->{sth} || $conf->{'запросы'} || {}; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#~ return |
127
|
|
|
|
|
|
|
#~ unless ($c_sth && ref($c_sth) eq 'HASH' && keys %$c_sth); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#~ my $sth = {}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#~ while (my ($db, $opt) = each %$c_dbh) { |
132
|
|
|
|
|
|
|
#~ while (my ($st, $sql) = each %{$opt->{sth}}) { |
133
|
|
|
|
|
|
|
#~ $sth->{$db}{$st} = $dbh->{$db}->prepare($sql);# $app->sth->{main}{...} |
134
|
|
|
|
|
|
|
#~ $app->log->debug("Подготовился запрос [app->sth->{$db}{$st}]"); |
135
|
|
|
|
|
|
|
#~ } |
136
|
|
|
|
|
|
|
#~ } |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#~ while (my ($db, $h) = each %$c_sth) { |
139
|
|
|
|
|
|
|
#~ while (my ($st, $sql) = each %$h) { |
140
|
|
|
|
|
|
|
#~ $sth->{$db}{$st} = $dbh->{$db}->prepare($sql);# $app->sth->{main}{...} |
141
|
|
|
|
|
|
|
#~ $app->log->debug("Подготовился запрос [app->sth->{$db}{$st}]"); |
142
|
|
|
|
|
|
|
#~ } |
143
|
|
|
|
|
|
|
#~ } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#~ $sth; |
146
|
|
|
|
|
|
|
#~ }; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub хуки {# Хуки из конфига |
150
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
151
|
0
|
|
|
|
|
|
my $conf = $app->config; |
152
|
0
|
|
0
|
|
|
|
my $hooks = $conf->{'mojo_hooks'} || $conf->{'mojo.hooks'} || $conf->{'mojo'}{'hooks'} || $conf->{'хуки'} |
153
|
|
|
|
|
|
|
|| return; |
154
|
0
|
|
|
|
|
|
while (my ($name, $sub) = each %$hooks) { |
155
|
0
|
0
|
|
|
|
|
if (ref $sub eq 'ARRAY') { |
156
|
|
|
|
|
|
|
$app->hook($name => $_) |
157
|
0
|
|
|
|
|
|
for @$sub; |
158
|
|
|
|
|
|
|
} else { |
159
|
0
|
|
|
|
|
|
$app->hook($name => $sub); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
$app->log->debug(sprintf("Applied hook%s [%s] from config", ref $sub eq 'ARRAY' ? "s (@{[ scalar @$sub]})" : '', $name)); |
|
0
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub сессия { |
168
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
169
|
0
|
|
|
|
|
|
my $conf = $app->config; |
170
|
0
|
|
0
|
|
|
|
my $session = $conf->{'mojo_session'} || $conf->{'mojo_sessions'} || $conf->{'mojo.session'} || $conf->{'mojo.sessions'} || $conf->{'mojo'}{'session'} || $conf->{'mojo'}{'sessions'} || $conf->{'сессии'} || $conf->{'сессия'} |
171
|
|
|
|
|
|
|
|| return; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
#~ $app->sessions->cookie_name($session->{'cookie_name'}) |
174
|
|
|
|
|
|
|
#~ if $session->{'cookie_name'}; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
#~ $app->sessions->default_expiration($session->{'default_expiration'}) # set expiry |
177
|
|
|
|
|
|
|
#~ if defined $session->{'default_expiration'}; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
while (my ($meth, $val) = each %$session) { |
180
|
|
|
|
|
|
|
next |
181
|
0
|
0
|
|
|
|
|
unless $app->sessions->can($meth); |
182
|
0
|
|
|
|
|
|
$app->sessions->$meth($val); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub маршруты { |
187
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
188
|
0
|
|
|
|
|
|
my $conf = $app->config; |
189
|
0
|
0
|
0
|
|
|
|
my $routes = $conf->{'mojo_routes'} || $conf->{'mojo.routes'} || $conf->{'mojo'}{'routes'} || $conf->{'routes'} || $conf->{'маршруты'} |
190
|
|
|
|
|
|
|
or return; |
191
|
0
|
|
|
|
|
|
my $app_routes = $app->routes; |
192
|
|
|
|
|
|
|
my $apply_route = sub { |
193
|
0
|
|
0
|
0
|
|
|
my $r = shift || $app_routes; |
194
|
0
|
|
|
|
|
|
my ($meth, $arg) = @_; |
195
|
0
|
|
|
|
|
|
my $nr; |
196
|
0
|
0
|
|
|
|
|
if (my $m = $r->can($meth)) { |
197
|
0
|
0
|
|
|
|
|
$nr = $r->$m($arg) unless ref($arg); |
198
|
0
|
0
|
|
|
|
|
$nr = $r->$m(cb => $arg) if ref($arg) eq 'CODE'; |
199
|
0
|
0
|
|
|
|
|
$nr = $r->$m(@$arg) if ref($arg) eq 'ARRAY'; |
200
|
0
|
0
|
|
|
|
|
$nr = $r->$m(%$arg) if ref($arg) eq 'HASH'; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} else { |
203
|
0
|
|
|
|
|
|
$app->log->warn("Can't method [$meth] for route",); |
204
|
|
|
|
|
|
|
} |
205
|
0
|
|
|
|
|
|
return $nr; |
206
|
0
|
|
|
|
|
|
}; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
for my $r (@$routes) { |
209
|
0
|
0
|
|
|
|
|
my $nr = $apply_route->($app_routes, @$r[0,1]) |
210
|
|
|
|
|
|
|
or next; |
211
|
0
|
|
|
|
|
|
$app->log->debug("Apply route [$r->[0] $r->[1]]"); |
212
|
0
|
|
|
|
|
|
for( my $i = 2; $i < @$r; $i += 2 ) { |
213
|
0
|
0
|
|
|
|
|
$nr = $apply_route->($nr, @$r[$i, $i+1]) |
214
|
|
|
|
|
|
|
or next; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub спейсы { |
220
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
221
|
0
|
|
|
|
|
|
my $conf = $app->config; |
222
|
0
|
|
0
|
|
|
|
my $ns = $conf->{'mojo_namespaces'} || $conf->{'mojo.namespaces'} || $conf->{'mojo'}{'namespaces'} || $conf->{'namespaces'} || $conf->{'ns'} || $conf->{'спейсы'} |
223
|
|
|
|
|
|
|
|| return; |
224
|
0
|
|
|
|
|
|
push @{$app->routes->namespaces}, @$ns; |
|
0
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub задачи { |
228
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
229
|
0
|
|
|
|
|
|
my $conf = $app->config; |
230
|
0
|
0
|
0
|
|
|
|
my $tasks = $conf->{'jobs'} || $conf->{'tasks'} || $conf->{'задачи'} |
231
|
|
|
|
|
|
|
or return; |
232
|
|
|
|
|
|
|
|
233
|
0
|
0
|
|
|
|
|
die "You have jobs and first enable plugin Minion" |
234
|
|
|
|
|
|
|
unless $app->renderer->get_helper('minion'); |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
while (my ($name, $sub) = each %$tasks) { |
237
|
0
|
|
|
|
|
|
$app->log->debug(sprintf("Applied task [%s] in [%s] from config", $name, $app->minion->add_task($name => $sub))); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
#~ $app->minion->reset; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub типы {#MIME |
244
|
0
|
|
|
0
|
0
|
|
my $app = shift; |
245
|
0
|
|
|
|
|
|
my $conf = $app->config; |
246
|
0
|
0
|
0
|
|
|
|
my $types = $conf->{'mojo_types'} || $conf->{'mojo.types'} || $conf->{'mojo'}{'types'} || $conf->{'types'} || $conf->{'типы'} |
247
|
|
|
|
|
|
|
or return; |
248
|
0
|
|
|
|
|
|
while (my ($name, $val) = each %$types) { |
249
|
0
|
|
|
|
|
|
$app->types->type($name => $val); |
250
|
0
|
|
|
|
|
|
$app->log->debug(sprintf("Applied type [%s] from config", $name)); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# overide only on my $path = $req->url->path->to_abs_string; |
255
|
|
|
|
|
|
|
sub Mojolicious::dispatch { |
256
|
0
|
|
|
0
|
1
|
|
my ($self, $c) = @_; |
257
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
my $plugins = $self->plugins->emit_hook(before_dispatch => $c); |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# Try to find a static file |
261
|
0
|
|
|
|
|
|
my $tx = $c->tx; |
262
|
0
|
0
|
0
|
|
|
|
$self->static->dispatch($c) and $plugins->emit_hook(after_static => $c) |
263
|
|
|
|
|
|
|
unless $tx->res->code; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# Start timer (ignore static files) |
266
|
0
|
|
|
|
|
|
my $stash = $c->stash; |
267
|
|
|
|
|
|
|
$c->helpers->log->debug(sub { |
268
|
0
|
|
|
0
|
|
|
my $req = $c->req; |
269
|
0
|
|
|
|
|
|
my $url = $req->url->to_abs; |
270
|
0
|
|
|
|
|
|
$c->helpers->timing->begin('mojo.timer'); |
271
|
|
|
|
|
|
|
#~ return sprintf qq{[%s] %s "%s://%s%s%s"}, |
272
|
|
|
|
|
|
|
#~ $req->request_id, $req->method, $url->scheme, $url->host, $url->port ? ":".$url->port : '', $url->path->to_route; |
273
|
0
|
|
|
|
|
|
return sprintf qq{%s "%s"}, $req->method, Mojo::Util::decode('UTF-8', Mojo::Util::url_unescape($url)); |
274
|
0
|
0
|
|
|
|
|
}) unless $stash->{'mojo.static'}; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# Routes |
277
|
0
|
|
|
|
|
|
$plugins->emit_hook(before_routes => $c); |
278
|
|
|
|
|
|
|
$c->helpers->reply->not_found |
279
|
0
|
0
|
0
|
|
|
|
unless $tx->res->code || $self->routes->dispatch($c) || $tx->res->code || $stash->{'mojo.rendered'}; |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
our $VERSION = '0.09021';# as to Mojolicious/100+0.000 |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=pod |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=encoding utf8 |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head1 Mojolicious::Che |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Доброго всем |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 VERSION |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
0.09021 |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 NAME |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Mojolicious::Che - Мой базовый модуль для приложений Mojolicious. Нужен только развернутый конфиг. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 SYNOPSIS |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# app.pl |
306
|
|
|
|
|
|
|
use lib 'lib'; |
307
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Che'; |
308
|
|
|
|
|
|
|
__PACKAGE__->new(config => 'lib/Config.pm')->start(); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 Config file |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
Порядок строк в этом конфиге соответствует исполнению в модуле! |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
{ |
316
|
|
|
|
|
|
|
'Проект'=>'Тест-проект', |
317
|
|
|
|
|
|
|
# mojo => { |
318
|
|
|
|
|
|
|
# defaults => |
319
|
|
|
|
|
|
|
# secrets => |
320
|
|
|
|
|
|
|
# mode=> |
321
|
|
|
|
|
|
|
# log => {level=>...} |
322
|
|
|
|
|
|
|
# static => {paths => [...]}, |
323
|
|
|
|
|
|
|
# renderer => {paths => [...], classes => [...], }, |
324
|
|
|
|
|
|
|
# session[s] => |
325
|
|
|
|
|
|
|
# has => |
326
|
|
|
|
|
|
|
# plugins => |
327
|
|
|
|
|
|
|
# hooks => |
328
|
|
|
|
|
|
|
# namespaces => |
329
|
|
|
|
|
|
|
# routes => |
330
|
|
|
|
|
|
|
# jobs => |
331
|
|
|
|
|
|
|
# types => |
332
|
|
|
|
|
|
|
# }, |
333
|
|
|
|
|
|
|
# or with prefix mojo_ |
334
|
|
|
|
|
|
|
# Default values for "stash" in Mojolicious::Controller, assigned for every new request. |
335
|
|
|
|
|
|
|
mojo_defaults => {layout=>'default',}, |
336
|
|
|
|
|
|
|
# 'шифры' => [ |
337
|
|
|
|
|
|
|
mojo_secrets => ['true 123 my app',], |
338
|
|
|
|
|
|
|
mojo_mode=> 'development', |
339
|
|
|
|
|
|
|
mojo_log=>{level => 'error'}, |
340
|
|
|
|
|
|
|
mojo_static_paths => ["static"], |
341
|
|
|
|
|
|
|
mojo_renderer_classes => ["Mojolicious::Foo::Fun"], |
342
|
|
|
|
|
|
|
# 'сессия'(или сессии) => |
343
|
|
|
|
|
|
|
mojo_session[s] => {cookie_name => 'EXX', default_expiration => 86400}, |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
# 'хазы' => 'Лет 500-700 назад был такой дикий степной торговый жадный народ ХАЗАРЫ. Столицей их "государства" был город Тьмутаракань, где-то на берегу моря Каспия. Потомки этих людей рассыпаны по странам России, Средней Азии, Европы. Есть мнение, что хазары присвоили себе название ЕВРЕИ, но это не те библейские кроткие евреи, а жадные потомки кроманьонцев' |
346
|
|
|
|
|
|
|
mojo_has => { |
347
|
|
|
|
|
|
|
foo => sub {my $app = shift; return 'is a bar';}, |
348
|
|
|
|
|
|
|
}, |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
# 'базы' => |
351
|
|
|
|
|
|
|
# will be as has! |
352
|
|
|
|
|
|
|
dbh=>{ |
353
|
|
|
|
|
|
|
'main' => { |
354
|
|
|
|
|
|
|
# DBI->connect(dsn, user, passwd, $attrs) |
355
|
|
|
|
|
|
|
connect => ["DBI:Pg:dbname=test;", "postgres", undef, { |
356
|
|
|
|
|
|
|
ShowErrorStatement => 1, |
357
|
|
|
|
|
|
|
AutoCommit => 1, |
358
|
|
|
|
|
|
|
RaiseError => 1, |
359
|
|
|
|
|
|
|
PrintError => 1, |
360
|
|
|
|
|
|
|
pg_enable_utf8 => 1, |
361
|
|
|
|
|
|
|
#mysql_enable_utf8 => 1, |
362
|
|
|
|
|
|
|
#mysql_auto_reconnect=>1, |
363
|
|
|
|
|
|
|
}], |
364
|
|
|
|
|
|
|
# or use Foo::Dbh; external defined dbh |
365
|
|
|
|
|
|
|
# dbh => Dbh->dbh, |
366
|
|
|
|
|
|
|
# will do on connect |
367
|
|
|
|
|
|
|
do => ['set datestyle to "ISO, DMY";',], |
368
|
|
|
|
|
|
|
# prepared sth will be as has $app->sth->{}{} |
369
|
|
|
|
|
|
|
sth => { |
370
|
|
|
|
|
|
|
foo => <
|
371
|
|
|
|
|
|
|
select * |
372
|
|
|
|
|
|
|
from foo |
373
|
|
|
|
|
|
|
where |
374
|
|
|
|
|
|
|
bar = ?; |
375
|
|
|
|
|
|
|
SQL |
376
|
|
|
|
|
|
|
}, |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
}, |
379
|
|
|
|
|
|
|
# 'запросы' => |
380
|
|
|
|
|
|
|
# prepared sth will be as has $app->sth->{}{} |
381
|
|
|
|
|
|
|
sth => { |
382
|
|
|
|
|
|
|
main => { |
383
|
|
|
|
|
|
|
now => "select now();" |
384
|
|
|
|
|
|
|
}, |
385
|
|
|
|
|
|
|
}, |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
# 'плугины'=> [ |
388
|
|
|
|
|
|
|
mojo_plugins=>[ |
389
|
|
|
|
|
|
|
['Foo::Bar'], |
390
|
|
|
|
|
|
|
[Foo::Bar::Plugin => opt1 => ..., opt2 => ...], |
391
|
|
|
|
|
|
|
['Foo::Plugin' => sub {<...returns config data list...>}], |
392
|
|
|
|
|
|
|
], |
393
|
|
|
|
|
|
|
# 'хуки' => |
394
|
|
|
|
|
|
|
mojo_hooks=>{ |
395
|
|
|
|
|
|
|
#~ before_dispatch => sub {1;}, |
396
|
|
|
|
|
|
|
}, |
397
|
|
|
|
|
|
|
# 'спейсы' => [...] |
398
|
|
|
|
|
|
|
namespaces => ['Space::Shattle'], |
399
|
|
|
|
|
|
|
# 'маршруты' => [...] |
400
|
|
|
|
|
|
|
routes => [ |
401
|
|
|
|
|
|
|
[get=>'/', to=> {cb=>sub{shift->render(format=>'txt', text=>'Hello friend!');},}], |
402
|
|
|
|
|
|
|
] |
403
|
|
|
|
|
|
|
#~ 'задачи'=> {#first enable plugin Minion |
404
|
|
|
|
|
|
|
jobs => { |
405
|
|
|
|
|
|
|
slow_log => sub { |
406
|
|
|
|
|
|
|
my ($job, $msg) = @_; |
407
|
|
|
|
|
|
|
sleep 5; |
408
|
|
|
|
|
|
|
$job->app->log->error(qq{slow_log "$msg"}); |
409
|
|
|
|
|
|
|
}, |
410
|
|
|
|
|
|
|
}, |
411
|
|
|
|
|
|
|
# или 'типы'=>{...} |
412
|
|
|
|
|
|
|
types => { |
413
|
|
|
|
|
|
|
docx => ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'], |
414
|
|
|
|
|
|
|
... |
415
|
|
|
|
|
|
|
}, |
416
|
|
|
|
|
|
|
}; |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
B inherits all attributes from L and implements the |
421
|
|
|
|
|
|
|
following new ones. |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=head2 dbh |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
Set DBI handlers from config B (или B<базы>) |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
my $dbh = $app->dbh->{main}; |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=head2 sth |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
Set prepared stattements from config B (или B<запросы>). |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
my $sth = $app->sth->{main}{foo}; |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
=head2 плугины |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
Apply the plugins. See L, L. |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=head1 METHODS |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
B inherits all methods from L and implements the following new ones. |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
=head2 сессия() |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
Session object config apply. See L, L. |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=head2 хазы() |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
Apply the has's. UTF names allow. |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=head2 хуки() |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
Apply the hooks. See L. |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
=head2 спейсы() |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
Apply the namespaces. Push @{$app->routes->namespaces} your namespaces. See L. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
namespaces => ['Space::Shattle'], |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=head2 маршруты() |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
Apply the routes. See L, L. |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
#~ 'маршруты' => [ |
466
|
|
|
|
|
|
|
'routes'=>[ |
467
|
|
|
|
|
|
|
[get=>'/', to=> {cb=>sub{shift->render(format=>'txt', text=>'Welcome!');},}], |
468
|
|
|
|
|
|
|
], |
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=head2 задачи() |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Apply the jobs. See L. |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
#~ 'задачи'=> {#first enable plugin Minion |
475
|
|
|
|
|
|
|
'jobs'=> { # or tasks |
476
|
|
|
|
|
|
|
slow_log => sub { |
477
|
|
|
|
|
|
|
my ($job, $msg) = @_; |
478
|
|
|
|
|
|
|
sleep 5; |
479
|
|
|
|
|
|
|
$job->app->log->error(qq{slow_log "$msg"}); |
480
|
|
|
|
|
|
|
}, |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
}, |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
=head типы() |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
Apply the new types. See L, L. |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
=head1 SEE ALSO |
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
L |
491
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
L |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=head1 AUTHOR |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Михаил Че (Mikhail Che), C<< >> |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=head1 BUGS / CONTRIBUTING |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. |
501
|
|
|
|
|
|
|
Pull requests also welcome. |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
=head1 COPYRIGHT |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
Copyright 2016+ Mikhail Che. |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
508
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=cut |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
1; |