blib/lib/Statocles/Command/bundle.pm

filter: Statementstmt 100% 39 / 39 Branchbran 92.8% 13 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 95.3% 61 / 64 CC 10 SCAR 17.5
CC
10
Cov
98%
bundle_theme
8.0
run
3.0
BEGIN
1.0
CRAP 5.8
« blib/lib/Statocles/Page/List.pm ↑ Summary blib/lib/Statocles/Command/build.pm »
1 package Statocles::Command::bundle;
2 4 our $VERSION = '0.099';
3 # ABSTRACT: Copy a default theme to this site to make changes
4  
5 4 ▶use Statocles::Base 'Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use File::Share qw( dist_dir );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶sub run {
Subroutine run: called CC=3 SCAR=11.0
Pod undocumented
9 4 my ( $self, @argv ) = @_;
10 4 my $what = $argv[0];
11 4 ▶ if ( $what eq 'theme' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "theme") 4 0 4
12 4 my $theme_name = $argv[1];
13 4 ▶ if ( !$theme_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($theme_name) 1 3 4
14 1 say STDERR "ERROR: No theme name!";
15 1 say STDERR "\nUsage:\n\tstatocles bundle theme <name>";
16 1 return 1;
17 }
18  
19 3 my $dest_dir = $self->site->theme->path;
20 3 $self->bundle_theme( $theme_name, $dest_dir, @argv[2..$#argv] );
21 3 say qq{Theme "$theme_name" written to "$dest_dir"};
22 }
23 3 return 0;
24 }
25  
26 5 ▶sub bundle_theme {
Subroutine bundle_theme: called CC=8 SCAR=20.8
Pod undocumented
27 5 my ( $class, $name, $dir, @files ) = @_;
28 5 my $theme_dest = Path::Tiny->new( $dir );
29 5 my $theme_root = Path::Tiny->new( dist_dir( 'Statocles' ), 'theme', $name );
30  
31 5 ▶ if ( !@files ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @files) { } 4 1 5
32 4 my $iter = $theme_root->iterator({ recurse => 1 });
33 4 ▶ while ( my $path = $iter->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = &$iter()) 120 4 124
34 120 ▶ next unless $path->is_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $path->is_file 28 92 120
35 92 my $relative = $path->relative( $theme_root );
36 92 push @files, $relative;
37 }
38 }
39 else {
40 1 @files = map { Path::Tiny->new( $_ ) } @files;
41 }
42  
43 5 for my $path ( @files ) {
44 96 my $abs_path = $path->absolute( $theme_root );
45 96 my $dest = $theme_dest->child( $path );
46 # Don't overwrite site-customized hooks
47 96 ▶ next if ( $abs_path->stat->size == 0 && $dest->exists );
Branch: 1 branch
BranchTrueFalseTotal
if $abs_path->stat->size == 0 and $dest->exists 5 91 96
Condition100%3/3
$abs_path->stat->size == 0 and $dest->exists
!ll&&!rl&&r
76155
MC/DC100%2/2
$abs_path->stat->size == 0 and $dest->exists
$abs_path->stat->size == 0 $dest->exists
Truth table100%3/3
A and B
A= $abs_path->stat->size == 0B= $dest->exists
ABresult
0X0
100
111
48 91 Statocles->log( debug => sprintf 'Copying theme file "%s" to "%s"', $path, $dest );
49 91 ▶ $dest->remove if $dest->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $dest->exists 18 73 91
50 91 $dest->parent->mkpath;
51 91 $abs_path->copy( $dest );
52 }
53 }
54  
55 4 1;
56  
57 __END__
« blib/lib/Statocles/Page/List.pm ↑ Summary blib/lib/Statocles/Command/build.pm »