| 1 | package Riji::CLI::NewEntry; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use feature ':5.10'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use IPC::Cmd (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Riji; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=10 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 3 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||
| 14 | 3 | my $subtitle = shift @argv; | |||||||||||||||||||||||||||
| 15 | 3 | ▶ | die "subtitle: $subtitle is not valid\n" if $subtitle && $subtitle =~ /[^-_a-zA-Z0-9.]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$subtitle and $subtitle =~ /[^-_a-zA-Z0-9.]/
MC/DC0%0/2
$subtitle and $subtitle =~ /[^-_a-zA-Z0-9.]/
$subtitle
$subtitle =~ /[^-_a-zA-Z0-9.]/
Truth table33%1/3
A and B
A= $subtitleB= $subtitle =~ /[^-_a-zA-Z0-9.]/
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | my $app = Riji->new; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | my $now = localtime; | |||||||||||||||||||||||||||
| 20 | 2 | my $dir = $app->model('Blog')->entry_path; | |||||||||||||||||||||||||||
| 21 | 2 | ▶ | $dir->mkpath unless $dir->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 2 | my $date_str = $now->strftime('%Y-%m-%d'); | |||||||||||||||||||||||||||
| 23 | 2 | my $file_format = "$dir/$date_str-%s.md"; | |||||||||||||||||||||||||||
| 24 | 2 | my $file; | |||||||||||||||||||||||||||
| 25 | 2 | ▶ | if ($subtitle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | $file = path(sprintf $file_format, $subtitle); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | else { | ||||||||||||||||||||||||||||
| 29 | 2 | my $seq = 1; | |||||||||||||||||||||||||||
| 30 | 2 | ▶ | $file = path(sprintf $file_format, sprintf('%02d', $seq++)) while !$file || -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $file or -e $file
MC/DC100%2/2
not $file or -e $file
not $file
-e $file
Truth table100%3/3
not(A) or B
A= not $fileB= -e $file
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | $file->spew(<<'...') unless -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | tags: blah | ||||||||||||||||||||||||||||
| 35 | --- | ||||||||||||||||||||||||||||
| 36 | # title | ||||||||||||||||||||||||||||
| 37 | ... | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | my $editor = $ENV{EDITOR}; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | $editor = $editor && IPC::Cmd::can_run($editor); | ||||||||||||||||||||||||||
|
Condition33%1/3
$editor && IPC::Cmd::can_run($editor)
MC/DC0%0/2
$editor && IPC::Cmd::can_run($editor)
$editor
IPC::Cmd::can_run($editor)
Truth table33%1/3
A && B
A= $editorB= IPC::Cmd::can_run($editor)
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | exec $editor, "$file" if $editor; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 2 | say "$file is created. Edit it!"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | 1; | |||||||||||||||||||||||||||