line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Contenticious; |
2
|
3
|
|
|
3
|
|
59149
|
use Mojo::Base 'Mojolicious'; |
|
3
|
|
|
|
|
151837
|
|
|
3
|
|
|
|
|
24
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.393'; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
557056
|
use Contenticious::Content; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
27
|
|
7
|
3
|
|
|
3
|
|
101
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1245
|
|
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
|
38934
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# find out config file name |
22
|
2
|
|
|
|
|
8
|
my $config_file = $ENV{CONTENTICIOUS_CONFIG}; |
23
|
2
|
|
33
|
|
|
6
|
$config_file //= $self->home->rel_file('config'); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# load config |
26
|
2
|
|
|
|
|
10
|
my $config = $self->plugin(Config => {file => $config_file}); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# prepare content |
29
|
2
|
|
33
|
|
|
4013
|
$self->pages_dir($config->{pages_dir} // $self->home->rel_file('pages')); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# dumping needs relative URLs |
32
|
2
|
|
|
|
|
54
|
$self->plugin('RelativeUrlFor'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# add content helper |
35
|
2
|
|
|
51
|
|
2882
|
$self->helper(contenticious => sub { $self->content }); |
|
51
|
|
|
|
|
90968
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# tell the renderer where to find templates |
38
|
2
|
|
|
|
|
152
|
$self->renderer->classes(['Contenticious']); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# perldoc renderer (to display Contenticious.pod for first-time-users) |
41
|
2
|
50
|
|
|
|
37
|
$self->plugin('PODViewer') if $self->config('perldoc'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# content action |
44
|
|
|
|
|
|
|
my $serve_content = sub { |
45
|
13
|
|
|
13
|
|
198640
|
my $c = shift; |
46
|
13
|
|
100
|
|
|
74
|
my $path = $c->param('cpath') // ''; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# delete format |
49
|
13
|
|
|
|
|
829
|
$path =~ s/\.html$//; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# found matching content node? |
52
|
13
|
|
|
|
|
61
|
my $content_node = $c->contenticious->find($path); |
53
|
13
|
100
|
|
|
|
34
|
unless (defined $content_node) { |
54
|
1
|
|
|
|
|
12
|
$c->reply->not_found; |
55
|
1
|
|
|
|
|
775
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# go |
59
|
|
|
|
|
|
|
$c->render( |
60
|
12
|
|
|
|
|
65
|
cpath => $path, |
61
|
|
|
|
|
|
|
content_node => $content_node, |
62
|
|
|
|
|
|
|
template => 'content', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# empty cache? |
66
|
12
|
50
|
|
|
|
9054
|
$c->contenticious->empty_cache unless $c->config('cached'); |
67
|
2
|
|
|
|
|
41498
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# content routes |
70
|
2
|
|
|
|
|
9
|
my $r = $self->routes; |
71
|
2
|
|
|
|
|
20
|
$r->get('/' => $serve_content); |
72
|
2
|
|
|
|
|
332
|
$r->get('/*cpath' => $serve_content)->name('content'); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__DATA__ |