File Coverage

blib/lib/Riji/CLI/Setup.pm
Criterion Covered Total %
statement 60 62 96.7
branch 7 12 58.3
condition 1 3 33.3
subroutine 12 12 100.0
pod 0 1 0.0
total 80 90 88.8


line stmt bran cond sub pod time code
1             package Riji::CLI::Setup;
2 4     4   4293 use feature ':5.10';
  4         20  
  4         432  
3 4     4   26 use strict;
  4         7  
  4         93  
4 4     4   21 use warnings;
  4         17  
  4         168  
5              
6 4     4   364 use Cwd qw/getcwd/;
  4         10  
  4         270  
7 4     4   1602 use File::Copy qw/copy/;
  4         7588  
  4         284  
8 4     4   3738 use File::Copy::Recursive qw/dircopy/;
  4         17006  
  4         328  
9 4     4   38 use File::Spec;
  4         8  
  4         82  
10 4     4   23 use IPC::Cmd ();
  4         8  
  4         60  
11 4     4   18 use Path::Tiny;
  4         9  
  4         178  
12              
13 4     4   22 use Riji;
  4         7  
  4         2131  
14              
15             sub run {
16 4     4 0 45 my ($class, @argv) = @_;
17              
18 4         11 my $force = grep {$_ eq '--force'} @argv;
  0         0  
19              
20 4         22 my $share_dir = Riji->share_dir;
21 4         82 my $setup_dir = getcwd;
22              
23 4 50 33     40 if (!$force && path($setup_dir)->children) {
24 0         0 die "you must run `riji setup` in empty directory or `riji setup --force`.\n";
25             }
26              
27             my $recurse644 = sub {
28 8     8   300 my $dir = shift;
29 8         43 my $itr = $dir->iterator({recurse => 1});
30 8         312 while (my $file = $itr->()) {
31 36 100       4230 next unless -f $file;
32 32         536 chmod 0644, $file;
33             }
34 4         963 };
35              
36 4         52 my $target_dir = File::Spec->catdir($setup_dir, 'share', 'tmpl');
37 4         35 dircopy(File::Spec->catdir($share_dir, 'tmpl'), $target_dir);
38 4         14423 $recurse644->(path($target_dir));
39              
40 4         302 $target_dir = File::Spec->catdir($setup_dir, 'article');
41 4         35 dircopy(File::Spec->catdir($share_dir, 'article'), $target_dir);
42 4         9956 $recurse644->(path($target_dir));
43              
44 4         296 copy(File::Spec->catfile($share_dir, 'riji.yml'), $setup_dir);
45 4         1979 copy(File::Spec->catfile($share_dir, 'README.md'), $setup_dir);
46              
47 4         1411 my $cpanfile = path($setup_dir, 'cpanfile');
48 4 50       171 unless (-f $cpanfile) {
49 4         250 $cpanfile->spew(qq{requires "Riji", "$Riji::VERSION";\n});
50             }
51              
52 4         2212 my $gitignore = path($setup_dir, '.gitignore');
53 4 50       166 unless (-f $gitignore) {
54 4         107 $gitignore->spew(".*\n!.gitignore\nlocal/\n*~\n*.swp\n");
55             }
56              
57 4 50       1559 my $git = IPC::Cmd::can_run('git') or die "git not found.\n";
58              
59 4 50       399238 unless (-e path($setup_dir)->child('.git')) {
60 4         82035 system($git, qw!init!);
61             }
62 4         49938 system($git, qw!add .!);
63 4         57842 system($git, qw/commit -m/, "initial blog commit");
64             }
65              
66             1;