blib/lib/Riji/CLI/Setup.pm

filter: Statementstmt 96.8% 61 / 63 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 87.3% 83 / 95 CC 9 SCAR 12.5
CC
9
Cov
89%
run
7.3
__ANON__
3.0
BEGIN
1.0
CRAP 3.5
« lib/Riji/Model/Article.pm ↑ Summary lib/Riji/Models.pm »
1 package Riji::CLI::Setup;
2 4 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Cwd qw/getcwd/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use File::Copy qw/copy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use File::Copy::Recursive qw/dircopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use IPC::Cmd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Riji;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶sub run {
Subroutine run: called CC=7 SCAR=19.9
Pod undocumented
16 4 my ($class, @argv) = @_;
17  
18 0 my $force = grep {$_ eq '--force'} @argv;
19  
20 4 my $share_dir = Riji->share_dir;
21 4 my $setup_dir = getcwd;
22  
23 4 ▶ if (!$force && path($setup_dir)->children) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $force and path($setup_dir)->children) 0 4 4
Condition33%1/3
not $force and path($setup_dir)->children
!ll&&!rl&&r
040
MC/DC0%0/2
not $force and path($setup_dir)->children
not $force path($setup_dir)->children
Truth table33%1/3
not(A) and B
A= not $forceB= path($setup_dir)->children
ABresult
0X0
100
111
24 0 die "you must run `riji setup` in empty directory or `riji setup --force`.\n";
25 }
26  
27 8 ▶ my $recurse644 = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
28 8 my $dir = shift;
29 8 my $itr = $dir->iterator({recurse => 1});
30 8 ▶ while (my $file = $itr->()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = &$itr()) 36 8 44
31 36 ▶ next unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 4 32 36
32 32 chmod 0644, $file;
33 }
34 4 };
35  
36 4 my $target_dir = File::Spec->catdir($setup_dir, 'share', 'tmpl');
37 4 dircopy(File::Spec->catdir($share_dir, 'tmpl'), $target_dir);
38 4 $recurse644->(path($target_dir));
39  
40 4 $target_dir = File::Spec->catdir($setup_dir, 'article');
41 4 dircopy(File::Spec->catdir($share_dir, 'article'), $target_dir);
42 4 $recurse644->(path($target_dir));
43  
44 4 copy(File::Spec->catfile($share_dir, 'riji.yml'), $setup_dir);
45 4 copy(File::Spec->catfile($share_dir, 'README.md'), $setup_dir);
46  
47 4 my $cpanfile = path($setup_dir, 'cpanfile');
48 4 ▶ unless (-f $cpanfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $cpanfile) 4 0 4
49 4 $cpanfile->spew(qq{requires "Riji", "$Riji::VERSION";\n});
50 }
51  
52 4 my $gitignore = path($setup_dir, '.gitignore');
53 4 ▶ unless (-f $gitignore) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $gitignore) 4 0 4
54 4 $gitignore->spew(".*\n!.gitignore\nlocal/\n*~\n*.swp\n");
55 }
56  
57 4 ▶ my $git = IPC::Cmd::can_run('git') or die "git not found.\n";
Branch: 1 branch
BranchTrueFalseTotal
my $git = IPC::Cmd::can_run("git") or die "git not found.\n" 4 0 4
58  
59 4 ▶ unless (-e path($setup_dir)->child('.git')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e path($setup_dir)->child(".git")) 4 0 4
60 4 system($git, qw!init!);
61 }
62 4 system($git, qw!add .!);
63 4 system($git, qw/commit -m/, "initial blog commit");
64 }
65  
66 4 1;
« lib/Riji/Model/Article.pm ↑ Summary lib/Riji/Models.pm »