line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bootylicious::Plugin::BootyConfig; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2753
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
80
|
|
4
|
3
|
|
|
3
|
|
24
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
93
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
15
|
use base 'Mojolicious::Plugin'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
354
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
20
|
use Mojolicious::Controller; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
30
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
4
|
|
|
4
|
1
|
197
|
my ($self, $app, $conf) = @_; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
|
|
22
|
my $c = Mojolicious::Controller->new(app => $app); |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
50
|
|
|
42
|
$conf ||= {}; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
27
|
$app->log->level('error'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Default plugins |
20
|
4
|
|
|
|
|
602
|
$app->plugin('PODRenderer', {no_perldoc => 1}); |
21
|
4
|
|
|
|
|
49579
|
$app->plugin('TagHelpers'); |
22
|
4
|
|
|
|
|
3911
|
$app->plugin( |
23
|
|
|
|
|
|
|
validator => { |
24
|
|
|
|
|
|
|
messages => { |
25
|
|
|
|
|
|
|
REQUIRED => 'Required', |
26
|
|
|
|
|
|
|
EMAIL_CONSTRAINT_FAILED => "Doesn't look like an email to me", |
27
|
|
|
|
|
|
|
URL_CONSTRAINT_FAILED => "Doesn't look like an url to me" |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
4
|
100
|
|
|
|
65097
|
$conf->{default} = $self->_default unless exists $conf->{default}; |
33
|
4
|
|
|
|
|
21
|
my $config = $app->plugin('JSONConfig' => $conf); |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
6274
|
$app->secrets([$config->{secret}]); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Config access |
38
|
|
|
|
|
|
|
$app->helper( |
39
|
|
|
|
|
|
|
config => sub { |
40
|
316
|
|
|
316
|
|
77584
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
316
|
100
|
|
|
|
736
|
if (@_) { |
43
|
308
|
50
|
|
|
|
1326
|
return $config->{$_[0]} if @_ == 1; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$config = {%$config, @_}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
8
|
|
|
|
|
36
|
return $config; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
59
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Set appropriate log level |
53
|
4
|
|
|
|
|
91
|
$app->log->level($config->{loglevel}); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Additional Perl modules |
56
|
4
|
|
|
|
|
62
|
$self->_setup_inc($config->{perl5lib}); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# CGI hack |
59
|
4
|
50
|
|
|
|
20
|
$ENV{SCRIPT_NAME} = $config->{base} if defined $config->{base}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Don't use set locale unless it is explicitly specified via a config file |
62
|
4
|
|
|
|
|
39
|
$ENV{LC_ALL} = 'C'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# set proper templates base dir, if defined |
65
|
3
|
|
|
|
|
11
|
push @{$app->renderer->paths}, $app->home->rel_file($config->{templates_directory}) |
66
|
4
|
100
|
|
|
|
19
|
if defined $config->{templates_directory}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# set proper public base dir, if defined |
69
|
3
|
|
|
|
|
14
|
push @{$app->static->paths}, $app->home->rel_file($config->{public_directory}) |
70
|
4
|
100
|
|
|
|
127
|
if defined $config->{public_directory}; |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
95
|
$app->defaults(title => '', description => '', layout => 'wrapper'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Parser helpers |
75
|
4
|
|
|
5
|
|
91
|
$app->helper(parsers => sub { $config->{_parsers} }); |
|
5
|
|
|
|
|
210
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$app->helper( |
78
|
|
|
|
|
|
|
add_parser => sub { |
79
|
4
|
|
|
4
|
|
206
|
my $self = shift; |
80
|
4
|
|
|
|
|
14
|
my ($ext, $cb) = @_; |
81
|
|
|
|
|
|
|
|
82
|
4
|
|
|
|
|
18
|
$config->{_parsers}->{$ext} = $cb; |
83
|
|
|
|
|
|
|
} |
84
|
4
|
|
|
|
|
79
|
); |
85
|
|
|
|
|
|
|
|
86
|
4
|
|
|
|
|
61
|
$app->plugin('booty_helpers'); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$c->add_parser( |
89
|
4
|
|
|
0
|
|
113
|
pod => sub { $app->renderer->helpers->{pod_to_html}->(undef, @_) }); |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
|
91
|
4
|
100
|
|
|
|
18
|
if (my $theme = $config->{theme}) { |
92
|
1
|
|
|
|
|
10
|
my $theme_class = join '::' => 'Bootylicious::Theme', |
93
|
|
|
|
|
|
|
Mojo::ByteStream->new($theme)->camelize; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
57
|
$app->renderer->classes([$theme_class]); |
96
|
1
|
|
|
|
|
16
|
$app->static->classes([$theme_class]); |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
28
|
$app->plugin($theme_class); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Load additional plugins |
102
|
4
|
|
|
|
|
47
|
$self->_load_plugins($app, $config->{plugins}); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _setup_inc { |
106
|
4
|
|
|
4
|
|
13
|
my $self = shift; |
107
|
4
|
|
|
|
|
9
|
my $perl5lib = shift; |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
|
|
|
21
|
return unless $perl5lib; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
0
|
push @INC, $_ for (ref $perl5lib eq 'ARRAY' ? @{$perl5lib} : $perl5lib); |
|
0
|
|
|
|
|
0
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _load_plugins { |
115
|
4
|
|
|
4
|
|
14
|
my $self = shift; |
116
|
4
|
|
|
|
|
15
|
my ($app, $plugins_arrayref) = @_; |
117
|
|
|
|
|
|
|
|
118
|
4
|
100
|
|
|
|
27
|
return unless $plugins_arrayref; |
119
|
1
|
50
|
|
|
|
4
|
$plugins_arrayref = [$plugins_arrayref] |
120
|
|
|
|
|
|
|
unless ref $plugins_arrayref eq 'ARRAY'; |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
3
|
my @plugins; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $prev; |
125
|
1
|
|
|
|
|
3
|
while (my $plugin = shift @{$plugins_arrayref}) { |
|
3
|
|
|
|
|
9
|
|
126
|
2
|
100
|
|
|
|
7
|
if (ref($plugin) eq 'HASH') { |
127
|
1
|
50
|
|
|
|
6
|
next unless $plugins[-1]; |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
4
|
$plugins[-1]->{args} = $plugin; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
else { |
132
|
1
|
|
|
|
|
5
|
push @plugins, {name => $plugin, args => {}}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
4
|
foreach my $plugin (@plugins) { |
137
|
1
|
|
|
|
|
5
|
$app->plugin($plugin->{name} => $plugin->{args}); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub _default { |
142
|
3
|
|
|
3
|
|
123
|
{ author => 'whoami', |
143
|
|
|
|
|
|
|
email => '', |
144
|
|
|
|
|
|
|
title => 'Just another blog', |
145
|
|
|
|
|
|
|
about => 'Perl hacker', |
146
|
|
|
|
|
|
|
description => 'I do not know if I need this', |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
cuttag => '[cut]', |
149
|
|
|
|
|
|
|
cuttext => 'Keep reading', |
150
|
|
|
|
|
|
|
pagelimit => 10, |
151
|
|
|
|
|
|
|
datefmt => '%a, %d %b %Y', |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
menu => [ |
154
|
|
|
|
|
|
|
index => '/', |
155
|
|
|
|
|
|
|
tags => '/tags.html', |
156
|
|
|
|
|
|
|
archive => '/articles.html' |
157
|
|
|
|
|
|
|
], |
158
|
|
|
|
|
|
|
footer => |
159
|
|
|
|
|
|
|
'Powered by Bootylicious', |
160
|
|
|
|
|
|
|
theme => '', |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
comments_enabled => 1, |
163
|
|
|
|
|
|
|
rss_enabled => 1, |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
meta => [], |
166
|
|
|
|
|
|
|
css => [], |
167
|
|
|
|
|
|
|
js => [], |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
strings => { |
170
|
|
|
|
|
|
|
'archive' => 'Archive', |
171
|
|
|
|
|
|
|
'archive-description' => 'Articles index', |
172
|
|
|
|
|
|
|
'tags' => 'Tags', |
173
|
|
|
|
|
|
|
'tags-description' => 'Tags overview', |
174
|
|
|
|
|
|
|
'tag' => 'Tag', |
175
|
|
|
|
|
|
|
'tag-description' => 'Articles with tag [_1]', |
176
|
|
|
|
|
|
|
'draft' => 'Draft', |
177
|
|
|
|
|
|
|
'permalink-to' => 'Permalink to', |
178
|
|
|
|
|
|
|
'later' => 'Later', |
179
|
|
|
|
|
|
|
'earlier' => 'Earlier', |
180
|
|
|
|
|
|
|
'not-found' => 'The page you are looking for was not found', |
181
|
|
|
|
|
|
|
'error' => 'Internal error occurred :(' |
182
|
|
|
|
|
|
|
}, |
183
|
|
|
|
|
|
|
template_handler => 'ep', |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
perl5lib => '', |
186
|
|
|
|
|
|
|
loglevel => 'error', |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
articles_directory => 'articles', |
189
|
|
|
|
|
|
|
pages_directory => 'pages', |
190
|
|
|
|
|
|
|
drafts_directory => 'drafts', |
191
|
|
|
|
|
|
|
public_directory => 'public', |
192
|
|
|
|
|
|
|
templates_directory => 'templates', |
193
|
|
|
|
|
|
|
}; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |