| 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
| |||||||||||||||||||||||||||||
| 12 | 4 | my $theme_name = $argv[1]; | |||||||||||||||||||||||||||
| 13 | 4 | ▶ | if ( !$theme_name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 32 | 4 | my $iter = $theme_root->iterator({ recurse => 1 }); | |||||||||||||||||||||||||||
| 33 | 4 | ▶ | while ( my $path = $iter->() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 120 | ▶ | next unless $path->is_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$abs_path->stat->size == 0 and $dest->exists
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
| |||||||||||||||||||||||||||||
| 48 | 91 | Statocles->log( debug => sprintf 'Copying theme file "%s" to "%s"', $path, $dest ); | |||||||||||||||||||||||||||
| 49 | 91 | ▶ | $dest->remove if $dest->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 91 | $dest->parent->mkpath; | |||||||||||||||||||||||||||
| 51 | 91 | $abs_path->copy( $dest ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||