line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::env; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
5051436
|
use strict; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
172
|
|
4
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
161
|
|
5
|
2
|
|
|
2
|
|
198
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
118
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
13
|
use Carp 'confess'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
363
|
|
8
|
2
|
|
|
2
|
|
671
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XML::LibXML::XPathContext; |
10
|
|
|
|
|
|
|
use XML::LibXSLT; |
11
|
|
|
|
|
|
|
use Scalar::Util 'weaken'; |
12
|
|
|
|
|
|
|
use meon::Web::Config; |
13
|
|
|
|
|
|
|
use meon::Web::SPc; |
14
|
|
|
|
|
|
|
use Path::Class 'dir'; |
15
|
|
|
|
|
|
|
use URI::Escape 'uri_escape_utf8'; |
16
|
|
|
|
|
|
|
use meon::Web::Member; |
17
|
|
|
|
|
|
|
use File::Find::Age; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $env = {}; |
20
|
|
|
|
|
|
|
sub get { return $env; } |
21
|
|
|
|
|
|
|
sub clear { $env = {}; return $env; } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
XML::LibXSLT->register_function( |
24
|
|
|
|
|
|
|
'http://web.meon.eu/', |
25
|
|
|
|
|
|
|
'uri_escape', |
26
|
|
|
|
|
|
|
sub { uri_escape_utf8($_[0]) } |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub xpc { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
my $xpc = XML::LibXML::XPathContext->new($env->{xml}); |
32
|
|
|
|
|
|
|
$xpc->registerNs('x', 'http://www.w3.org/1999/xhtml'); |
33
|
|
|
|
|
|
|
$xpc->registerNs('w', 'http://web.meon.eu/'); |
34
|
|
|
|
|
|
|
$xpc->registerNs('u', 'http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3AAuthentication%3A%3AStore%3A%3AUserXML'); |
35
|
|
|
|
|
|
|
return $xpc; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub hostname { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
$env->{hostname} = shift |
41
|
|
|
|
|
|
|
if @_; |
42
|
|
|
|
|
|
|
return $env->{hostname} // confess('unset'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub current_dir { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
return $self->xml_file->dir; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub current_path { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
$env->{current_path} = shift |
53
|
|
|
|
|
|
|
if @_; |
54
|
|
|
|
|
|
|
return $env->{current_path} // confess('unset'); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub hostname_dir_name { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
$env->{hostname_dir_name} = shift |
60
|
|
|
|
|
|
|
if @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
unless (defined($env->{hostname_dir_name})) { |
63
|
|
|
|
|
|
|
$env->{hostname_dir_name} = meon::Web::Config->hostname_to_folder($self->hostname); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
return $env->{hostname_dir_name}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub hostname_dir { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
$env->{hostname_dir} = shift |
71
|
|
|
|
|
|
|
if @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
unless (defined($env->{hostname_dir})) { |
74
|
|
|
|
|
|
|
my $hostname_dir_name = meon::Web::Config->hostname_to_folder($self->hostname); |
75
|
|
|
|
|
|
|
$env->{hostname_dir} = dir(meon::Web::SPc->srvdir, 'www', 'meon-web', $hostname_dir_name)->absolute->resolve; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
return $env->{hostname_dir}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub content_dir { |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
$env->{content_dir} = shift |
83
|
|
|
|
|
|
|
if @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$env->{content_dir} //= dir($self->hostname_dir,'content'); |
86
|
|
|
|
|
|
|
return $env->{content_dir}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub static_dir { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
$env->{static_dir} = shift |
92
|
|
|
|
|
|
|
if @_; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$env->{static_dir} //= dir($self->hostname_dir,'www','static'); |
95
|
|
|
|
|
|
|
return $env->{static_dir}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub profiles_dir { |
99
|
|
|
|
|
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
$env->{profiles_dir} //= dir($self->content_dir, 'members', 'profile'); |
101
|
|
|
|
|
|
|
return $env->{profiles_dir}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub xml_file { |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
$env->{xml_file} = shift |
107
|
|
|
|
|
|
|
if @_; |
108
|
|
|
|
|
|
|
return $env->{xml_file} // confess('unset'); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub xml { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
$env->{xml} //= XML::LibXML->load_xml(location => $self->xml_file); |
114
|
|
|
|
|
|
|
return $env->{xml}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub stash { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
if (@_) { |
120
|
|
|
|
|
|
|
$env->{stash} = shift @_; |
121
|
|
|
|
|
|
|
weaken($env->{stash}); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return $env->{stash} // confess('unset'); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub user { |
128
|
|
|
|
|
|
|
my $self = shift; |
129
|
|
|
|
|
|
|
if (@_) { |
130
|
|
|
|
|
|
|
$env->{user} = shift @_; |
131
|
|
|
|
|
|
|
weaken($env->{user}); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
return $env->{user}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub all_members { |
137
|
|
|
|
|
|
|
my $self = shift; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my @members; |
140
|
|
|
|
|
|
|
my $profiles_dir = $self->profiles_dir; |
141
|
|
|
|
|
|
|
return unless -d $profiles_dir; |
142
|
|
|
|
|
|
|
foreach my $username_dir ($profiles_dir->children(no_hidden => 1)) { |
143
|
|
|
|
|
|
|
next unless $username_dir->is_dir; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $username = $username_dir->basename; |
146
|
|
|
|
|
|
|
my $member = meon::Web::Member->new( |
147
|
|
|
|
|
|
|
members_folder => $profiles_dir, |
148
|
|
|
|
|
|
|
username => $username, |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
push(@members, $member) |
152
|
|
|
|
|
|
|
if (eval { $member->xml }); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
return @members; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub hostname_config { |
158
|
|
|
|
|
|
|
my $self = shift; |
159
|
|
|
|
|
|
|
return meon::Web::Config->get->{$self->hostname_dir_name} // {}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub static_dir_mtime { |
163
|
|
|
|
|
|
|
my $self = shift; |
164
|
|
|
|
|
|
|
$env->{static_dir_mtime} = shift |
165
|
|
|
|
|
|
|
if @_; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# ignore generated files |
168
|
|
|
|
|
|
|
my $ages = File::Find::Age->in($self->static_dir); |
169
|
|
|
|
|
|
|
while ($ages->[-1]->{file} =~ m{/meon-Web-merged\.(js|css)$}) { |
170
|
|
|
|
|
|
|
pop($ages); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$env->{static_dir_mtime} //= $ages->[-1]->{mtime} // '-'; |
174
|
|
|
|
|
|
|
return $env->{static_dir_mtime}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |