line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious; |
2
|
3
|
|
|
3
|
|
29033
|
use Mojo::Base 'Mojolicious'; |
|
3
|
|
|
|
|
6398
|
|
|
3
|
|
|
|
|
15
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.39'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
402032
|
use Contenticious::Content; |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
26
|
|
7
|
3
|
|
|
3
|
|
82
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
979
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has pages_dir => sub { croak 'no pages_dir given' }; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has content => sub { my $self = shift; |
12
|
|
|
|
|
|
|
return Contenticious::Content->new( |
13
|
|
|
|
|
|
|
pages_dir => $self->pages_dir, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# init web app |
18
|
|
|
|
|
|
|
sub startup { |
19
|
2
|
|
|
2
|
1
|
22596
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# find out config file name |
22
|
2
|
|
|
|
|
9
|
my $config_file = $ENV{CONTENTICIOUS_CONFIG}; |
23
|
2
|
|
33
|
|
|
9
|
$config_file //= $self->home->rel_file('config'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# load config |
26
|
2
|
|
|
|
|
11
|
my $config = $self->plugin(Config => {file => $config_file}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# prepare content |
29
|
2
|
|
33
|
|
|
3733
|
$self->pages_dir($config->{pages_dir} // $self->home->rel_dir('pages')); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# dumping needs relative URLs |
32
|
2
|
|
|
|
|
13
|
$self->plugin('RelativeUrlFor'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# add content helper |
35
|
2
|
|
|
51
|
|
2189
|
$self->helper(contenticious => sub { $self->content }); |
|
51
|
|
|
|
|
56515
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# tell the renderer where to find templates |
38
|
2
|
|
|
|
|
20
|
$self->renderer->classes(['Contenticious']); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# perldoc renderer (to display Contenticious.pod for first-time-users) |
41
|
2
|
50
|
|
|
|
19
|
$self->plugin('PODRenderer') if $self->config('perldoc'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# content action |
44
|
|
|
|
|
|
|
my $serve_content = sub { |
45
|
13
|
|
|
13
|
|
153024
|
my $c = shift; |
46
|
13
|
|
100
|
|
|
52
|
my $path = $c->param('cpath') // ''; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# delete format |
49
|
13
|
|
|
|
|
578
|
$path =~ s/\.html$//; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# found matching content node? |
52
|
13
|
|
|
|
|
78
|
my $content_node = $c->contenticious->find($path); |
53
|
13
|
100
|
|
|
|
31
|
unless (defined $content_node) { |
54
|
1
|
|
|
|
|
13
|
$c->reply->not_found; |
55
|
1
|
|
|
|
|
549
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# go |
59
|
|
|
|
|
|
|
$c->render( |
60
|
12
|
|
|
|
|
50
|
cpath => $path, |
61
|
|
|
|
|
|
|
content_node => $content_node, |
62
|
|
|
|
|
|
|
template => 'content', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# empty cache? |
66
|
12
|
50
|
|
|
|
6158
|
$c->contenticious->empty_cache unless $c->config('cached'); |
67
|
2
|
|
|
|
|
29262
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# content routes |
70
|
2
|
|
|
|
|
7
|
my $r = $self->routes; |
71
|
2
|
|
|
|
|
17
|
$r->get('/' => $serve_content); |
72
|
2
|
|
|
|
|
192
|
$r->get('/*cpath' => $serve_content)->name('content'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__DATA__ |