line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Riji::CLI::NewEntry; |
2
|
1
|
|
|
1
|
|
197075
|
use feature ':5.10'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
147
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use IPC::Cmd (); |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
5
|
use Path::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
8
|
1
|
|
|
1
|
|
546
|
use Time::Piece; |
|
1
|
|
|
|
|
9692
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
477
|
use Riji; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
332
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub run { |
13
|
1
|
|
|
1
|
0
|
2588
|
my ($class, @argv) = @_; |
14
|
1
|
|
|
|
|
15
|
my $subtitle = shift @argv; |
15
|
1
|
50
|
33
|
|
|
18
|
die "subtitle: $subtitle is not valid\n" if $subtitle && $subtitle =~ /[^-_a-zA-Z0-9.]/; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
54
|
my $app = Riji->new; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
2968
|
my $now = localtime; |
20
|
1
|
|
|
|
|
191
|
my $dir = $app->model('Blog')->entry_path; |
21
|
1
|
50
|
|
|
|
141
|
$dir->mkpath unless $dir->exists; |
22
|
1
|
|
|
|
|
70
|
my $date_str = $now->strftime('%Y-%m-%d'); |
23
|
1
|
|
|
|
|
194
|
my $file_format = "$dir/$date_str-%s.md"; |
24
|
1
|
|
|
|
|
14
|
my $file; |
25
|
1
|
50
|
|
|
|
7
|
if ($subtitle) { |
26
|
0
|
|
|
|
|
0
|
$file = path(sprintf $file_format, $subtitle); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
1
|
|
|
|
|
7
|
my $seq = 1; |
30
|
1
|
|
66
|
|
|
30
|
$file = path(sprintf $file_format, sprintf('%02d', $seq++)) while !$file || -e $file; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
98
|
$file->spew(<<'...') unless -e $file; |
34
|
|
|
|
|
|
|
tags: blah |
35
|
|
|
|
|
|
|
--- |
36
|
|
|
|
|
|
|
# title |
37
|
|
|
|
|
|
|
... |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
858
|
my $editor = $ENV{EDITOR}; |
40
|
1
|
|
33
|
|
|
7
|
$editor = $editor && IPC::Cmd::can_run($editor); |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
4
|
exec $editor, "$file" if $editor; |
43
|
1
|
|
|
|
|
11
|
say "$file is created. Edit it!"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |