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