line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
380
|
use FindBin; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
3
|
use Cwd; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
5
|
1
|
|
|
1
|
|
406
|
use lib "$FindBin::Bin/lib"; |
|
1
|
|
|
|
|
511
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
501
|
use Mojolicious::Lite; |
|
1
|
|
|
|
|
67878
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
9488
|
use Mojo::Util qw(md5_sum spurt); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
8
|
1
|
|
|
1
|
|
3
|
use Mojo::Loader qw(data_section); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
391
|
use Bootylicious; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
10
|
1
|
|
|
1
|
|
366
|
use Bootylicious::Timestamp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
app->home->parse($ENV{BOOTYLICIOUS_HOME} || getcwd()); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
unshift @{app->plugins->namespaces}, 'Bootylicious::Plugin'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
plugin 'booty_config' => {file => app->home->rel_file('bootylicious.conf')}; |
17
|
|
|
|
|
|
|
plugin 'markdown_parser'; |
18
|
|
|
|
|
|
|
plugin 'model'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $ALIAS_RE = qr/[a-zA-Z0-9-_]+/; |
21
|
|
|
|
|
|
|
my $TAG_RE = qr/[\w\s-]+/; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if (@ARGV && $ARGV[0] eq '--create-config') { |
24
|
|
|
|
|
|
|
if (-e 'bootylicious.conf') { |
25
|
|
|
|
|
|
|
die "bootylicious.conf already exists\n"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
spurt(data_section(__PACKAGE__, 'bootylicious.conf'), 'bootylicious.conf'); |
29
|
|
|
|
|
|
|
exit; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
get '/' => \&index => 'root'; |
33
|
|
|
|
|
|
|
get '/index' => \&index => 'index'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub index { |
36
|
3
|
|
|
3
|
|
21209
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
11
|
my $timestamp = $self->param('timestamp'); |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
461
|
my $pager = $self->get_articles(timestamp => $timestamp); |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
37
|
$self->stash(articles => $pager->articles, pager => $pager); |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
52
|
$self->render_smart('index'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
get '/articles/:year/:month' => [year => qr/\d+/, month => qr/\d+/] => |
48
|
|
|
|
|
|
|
{year => undef, month => undef} => sub { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $year = $self->stash('year'); |
52
|
|
|
|
|
|
|
my $month = $self->stash('month'); |
53
|
|
|
|
|
|
|
my $archive = $self->get_archive(year => $year, month => $month); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->stash(archive => $archive); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->render_smart; |
58
|
|
|
|
|
|
|
} => 'articles'; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
get '/articles/:year/:month/:alias' => |
61
|
|
|
|
|
|
|
[year => qr/\d+/, month => qr/\d+/, alias => $ALIAS_RE] => sub { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $article = $self->get_article(@{$self->stash}{qw/year month alias/}); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $self->reply->not_found unless $article; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$self->stash(article => $article); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self->render_smart; |
71
|
|
|
|
|
|
|
} => 'article'; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
post '/articles/:year/:month/:alias/comment' => sub { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return $self->reply->not_found unless $self->comments_enabled; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $article = $self->get_article(@{$self->stash}{qw/year month alias/}); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return $self->reply->not_found unless $article && $article->comments_enabled; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $validator = $self->create_validator; |
83
|
|
|
|
|
|
|
my $comment_name = md5_sum($article->created->year, $article->created->month, $article->name); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$validator->field('author')->required(1); |
86
|
|
|
|
|
|
|
$validator->field('email')->email(1); |
87
|
|
|
|
|
|
|
$validator->field('content')->length(0); # bot protection |
88
|
|
|
|
|
|
|
$validator->field($comment_name)->required(1); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
return $self->render('article', article => $article) |
91
|
|
|
|
|
|
|
unless $self->validate($validator); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $comment_params = $validator->values; |
94
|
|
|
|
|
|
|
$comment_params->{content} = delete $comment_params->{$comment_name}; |
95
|
|
|
|
|
|
|
my $comment = $article->comment(%$comment_params); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return $self->redirect_to($self->href_to_article($article) |
98
|
|
|
|
|
|
|
->fragment('comment-' . $comment->number)); |
99
|
|
|
|
|
|
|
} => 'comment'; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
get '/comments' => sub { |
102
|
|
|
|
|
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return $self->reply->not_found unless $self->comments_enabled; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$self->render_smart; |
107
|
|
|
|
|
|
|
} => 'comments'; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
get '/tags/:tag' => [tag => $TAG_RE] => sub { |
110
|
|
|
|
|
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $tag = $self->stash('tag'); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $timestamp = $self->param('timestamp'); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $pager = $self->get_articles_by_tag($tag, timestamp => $timestamp); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $self->reply->not_found unless $pager->articles->size; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$self->stash(articles => $pager->articles, pager => $pager); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$self->render_smart; |
123
|
|
|
|
|
|
|
} => 'tag'; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
get '/tags' => sub { |
126
|
|
|
|
|
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
my $cloud = $self->get_tag_cloud; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
$self->stash(tags => $cloud); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$self->render_smart; |
133
|
|
|
|
|
|
|
} => 'tags'; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
get '/pages/:name' => [name => $ALIAS_RE] => sub { |
136
|
|
|
|
|
|
|
my $self = shift; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $name = $self->stash('name'); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my $page = $self->get_page($name); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
return $self->reply->not_found unless $page; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$self->stash(page => $page); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
$self->render_smart; |
147
|
|
|
|
|
|
|
} => 'page'; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
get '/drafts/:name' => [name => $ALIAS_RE] => sub { |
150
|
|
|
|
|
|
|
my $self = shift; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $name = $self->stash('name'); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $draft = $self->get_draft($name); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return $self->reply->not_found unless $draft; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$self->stash(draft => $draft); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$self->render_smart; |
161
|
|
|
|
|
|
|
} => 'draft'; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
app->start; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__DATA__ |