File Coverage

/root/.cpan/build/Riji-v1.1.4-0/lib/Riji/CLI/NewEntry.pm
Criterion Covered Total %
statement 39 40 97.5
branch 5 10 50.0
condition 5 9 55.5
subroutine 8 8 100.0
pod 0 1 0.0
total 57 68 83.8


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