lib/Riji/CLI/NewEntry.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 58.3% 7 / 12 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 80.5% 62 / 77 CC 10 SCAR 19.8
CC
10
Cov
84%
run
11.6
BEGIN
1.0
BEGIN
1.0
CRAP 7.2
« lib/Riji/Model/Blog.pm ↑ Summary lib/Riji.pm »
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
BranchTrueFalseTotal
if $subtitle and $subtitle =~ /[^-_a-zA-Z0-9.]/ 0 3 3
Condition33%1/3
$subtitle and $subtitle =~ /[^-_a-zA-Z0-9.]/
!ll&&!rl&&r
300
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.]/
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $dir->exists 0 2 2
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
BranchTrueFalseTotal
if ($subtitle) { } 0 2 2
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
BranchTrueFalseTotal
!$file || -e $file and do { $file = path(sprintf($file_format, sprintf("%02d", $seq++))) } 3 2 5
Condition100%3/3
not $file or -e $file
l!l&&r!l&&!r
212
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
ABresult
1X1
011
000
31 }
32  
33 2 ▶ $file->spew(<<'...') unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 2 0 2
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)
!ll&&!rl&&r
200
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)
ABresult
0X0
100
111
41  
42 2 ▶ exec $editor, "$file" if $editor;
Branch: 1 branch
BranchTrueFalseTotal
if $editor 0 2 2
43 2 say "$file is created. Edit it!";
44 }
45  
46 3 1;
« lib/Riji/Model/Blog.pm ↑ Summary lib/Riji.pm »