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   327077 use feature ':5.10';
  4         8  
  4         729  
3 4     4   59 use strict;
  4         11  
  4         168  
4 4     4   52 use warnings;
  4         10  
  4         258  
5              
6 4     4   27 use Cwd qw/getcwd/;
  4         7  
  4         365  
7 4     4   1800 use File::Copy qw/copy/;
  4         12489  
  4         353  
8 4     4   2803 use File::Copy::Recursive qw/dircopy/;
  4         22227  
  4         352  
9 4     4   33 use File::Spec;
  4         7  
  4         126  
10 4     4   25 use IPC::Cmd ();
  4         8  
  4         88  
11 4     4   20 use Path::Tiny;
  4         7  
  4         215  
12              
13 4     4   26 use Riji;
  4         8  
  4         3010  
14              
15             sub run {
16 4     4 0 51 my ($class, @argv) = @_;
17              
18 4         15 my $force = grep {$_ eq '--force'} @argv;
  0         0  
19              
20 4         27 my $share_dir = Riji->share_dir;
21 4         100 my $setup_dir = getcwd;
22              
23 4 50 33     48 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   489 my $dir = shift;
29 8         54 my $itr = $dir->iterator({recurse => 1});
30 8         356 while (my $file = $itr->()) {
31 36 100       5229 next unless -f $file;
32 32         501 chmod 0644, $file;
33             }
34 4         1172 };
35              
36 4         56 my $target_dir = File::Spec->catdir($setup_dir, 'share', 'tmpl');
37 4         43 dircopy(File::Spec->catdir($share_dir, 'tmpl'), $target_dir);
38 4         20863 $recurse644->(path($target_dir));
39              
40 4         331 $target_dir = File::Spec->catdir($setup_dir, 'article');
41 4         65 dircopy(File::Spec->catdir($share_dir, 'article'), $target_dir);
42 4         15165 $recurse644->(path($target_dir));
43              
44 4         393 copy(File::Spec->catfile($share_dir, 'riji.yml'), $setup_dir);
45 4         2667 copy(File::Spec->catfile($share_dir, 'README.md'), $setup_dir);
46              
47 4         2212 my $cpanfile = path($setup_dir, 'cpanfile');
48 4 50       243 unless (-f $cpanfile) {
49 4         276 $cpanfile->spew(qq{requires "Riji", "$Riji::VERSION";\n});
50             }
51              
52 4         3853 my $gitignore = path($setup_dir, '.gitignore');
53 4 50       228 unless (-f $gitignore) {
54 4         223 $gitignore->spew(".*\n!.gitignore\nlocal/\n*~\n*.swp\n");
55             }
56              
57 4 50       3599 my $git = IPC::Cmd::can_run('git') or die "git not found.\n";
58              
59 4 50       506214 unless (-e path($setup_dir)->child('.git')) {
60 4         73893 system($git, qw!init!);
61             }
62 4         73334 system($git, qw!add .!);
63 4         113795 system($git, qw/commit -m/, "initial blog commit");
64             }
65              
66             1;