line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Config; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5260621
|
use strict; |
|
2
|
|
|
|
|
27
|
|
|
2
|
|
|
|
|
195
|
|
4
|
2
|
|
|
2
|
|
27
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
200
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1160
|
use meon::Web::SPc; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
7
|
2
|
|
|
2
|
|
1061
|
use Config::INI::Reader; |
|
2
|
|
|
|
|
61098
|
|
|
2
|
|
|
|
|
25
|
|
8
|
2
|
|
|
2
|
|
71
|
use File::Basename 'basename'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
174
|
|
9
|
2
|
|
|
2
|
|
446
|
use Log::Log4perl; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Path::Class 'file', 'dir'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Log::Log4perl::init( |
13
|
|
|
|
|
|
|
File::Spec->catfile( |
14
|
|
|
|
|
|
|
meon::Web::SPc->sysconfdir, 'meon', 'web-log4perl.conf' |
15
|
|
|
|
|
|
|
) |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $config = Config::INI::Reader->read_file( |
19
|
|
|
|
|
|
|
File::Spec->catfile( |
20
|
|
|
|
|
|
|
meon::Web::SPc->sysconfdir, 'meon', 'web-config.ini' |
21
|
|
|
|
|
|
|
) |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
foreach my $hostname_dir_name (keys %{$config->{domains} || {}}) { |
24
|
|
|
|
|
|
|
my $hostname_dir = File::Spec->catfile( |
25
|
|
|
|
|
|
|
meon::Web::SPc->srvdir, 'www', 'meon-web', $hostname_dir_name |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
my $hostname_dir_config = File::Spec->catfile( |
28
|
|
|
|
|
|
|
$hostname_dir, 'config.ini' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
if (-e $hostname_dir_config) { |
31
|
|
|
|
|
|
|
$config->{$hostname_dir_name} = Config::INI::Reader->read_file( |
32
|
|
|
|
|
|
|
$hostname_dir_config |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
unless (Run::Env->dev) { |
35
|
|
|
|
|
|
|
if (my $js_dir = $config->{$hostname_dir_name}->{main}->{'js-dir'}) { |
36
|
|
|
|
|
|
|
$js_dir = dir($hostname_dir, $js_dir); |
37
|
|
|
|
|
|
|
my $merged_js = ''; |
38
|
|
|
|
|
|
|
foreach my $js_file (sort $js_dir->children(no_hidden => 1)) { |
39
|
|
|
|
|
|
|
$merged_js .= '/* '.$js_file." */\n\n".$js_file->slurp.";\n\n"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
my $js_merged_file = file($hostname_dir, 'www','static','meon-Web-merged.js'); |
42
|
|
|
|
|
|
|
$js_merged_file->spew($merged_js); |
43
|
|
|
|
|
|
|
system("cat $js_merged_file | yui-compressor --type js --charset UTF-8 -o $js_merged_file.tmp && mv $js_merged_file.tmp $js_merged_file") |
44
|
|
|
|
|
|
|
and die 'failed to minify js '.$!; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
if (my $css_dir = $config->{$hostname_dir_name}->{main}->{'css-dir'}) { |
47
|
|
|
|
|
|
|
$css_dir = dir($hostname_dir, $css_dir); |
48
|
|
|
|
|
|
|
my $merged_css = ''; |
49
|
|
|
|
|
|
|
foreach my $css_file (sort $css_dir->children(no_hidden => 1)) { |
50
|
|
|
|
|
|
|
$merged_css .= '/* '.$css_file." */\n\n".$css_file->slurp."\n\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
my $css_merged_file = file($hostname_dir, 'www','static','meon-Web-merged.css'); |
53
|
|
|
|
|
|
|
$css_merged_file->spew($merged_css); |
54
|
|
|
|
|
|
|
system("cat $css_merged_file | yui-compressor --type css --charset UTF-8 -o $css_merged_file.tmp && mv $css_merged_file.tmp $css_merged_file") |
55
|
|
|
|
|
|
|
and die 'failed to minify css '.$!; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get { |
62
|
|
|
|
|
|
|
return $config; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my %h2f; |
66
|
|
|
|
|
|
|
sub hostname_to_folder { |
67
|
|
|
|
|
|
|
my ($class, $hostname) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
unless (%h2f) { |
70
|
|
|
|
|
|
|
foreach my $folder (keys %{$config->{domains} || {}}) { |
71
|
|
|
|
|
|
|
my @domains = map { $_ =~s/^\s+//;$_ =~s/\s+$//; $_ } split(/\s*,\s*/, $config->{domains}{$folder}); |
72
|
|
|
|
|
|
|
foreach my $domain (@domains) { |
73
|
|
|
|
|
|
|
$h2f{$domain} = $folder; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return $h2f{$hostname}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |