| 1 | package App::VTide::Command::Init; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # Created on: 2016-01-30 15:06:31 | ||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use version; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use File::chdir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | ▶ | use YAML::Syck; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | extends 'App::VTide::Command'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | our $VERSION = version->new('1.0.6'); | |||||||||||||||||||
| 21 | 1 | our $NAME = 'init'; | |||||||||||||||||||
| 22 | 1 | our $OPTIONS = [ | |||||||||||||||||||
| 23 | 'name|n=s', | ||||||||||||||||||||
| 24 | 'dir|d=s', | ||||||||||||||||||||
| 25 | 'windows|w=i', | ||||||||||||||||||||
| 26 | 'force|f!', | ||||||||||||||||||||
| 27 | 'verbose|v+', | ||||||||||||||||||||
| 28 | ]; | ||||||||||||||||||||
| 29 | 0 | ▶ | sub details_sub { return ( $NAME, $OPTIONS )}; | ||||||||||||||||||
|
Subroutine
details_sub: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 32 | 0 | my ($self) = @_; | |||||||||||||||||||
| 33 | 0 | ▶ | my $dir = path( $self->defaults->{dir} || '.' )->absolute; | ||||||||||||||||||
|
Condition0%0/2
$self->defaults->{'dir'} || '.'
MC/DC0%0/1
$self->defaults->{'dir'} || '.'
$self->defaults->{'dir'}
Truth table0%0/2
A
A= $self->defaults->{'dir'}
| |||||||||||||||||||||
| 34 | 0 | my $file = $dir->path( '.vtide.yml' ); | |||||||||||||||||||
| 35 | 0 | ▶ | my $count = $self->defaults->{windows} || 4; | ||||||||||||||||||
|
Condition0%0/2
$self->defaults->{'windows'} || 4
MC/DC0%0/1
$self->defaults->{'windows'} || 4
$self->defaults->{'windows'}
Truth table0%0/2
A
A= $self->defaults->{'windows'}
| |||||||||||||||||||||
| 36 | 0 | ▶ | my $name = $self->defaults->{name} || $dir->basename; | ||||||||||||||||||
|
Condition0%0/3
$self->defaults->{'name'} || $dir->basename
MC/DC0%0/2
$self->defaults->{'name'} || $dir->basename
$self->defaults->{'name'}
$dir->basename
Truth table0%0/3
A || B
A= $self->defaults->{'name'}B= $dir->basename
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | $self->hooks->run('init_name', \$name); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | my $config = { | ||||||||||||||||||||
| 41 | name => $name, | ||||||||||||||||||||
| 42 | count => $count, | ||||||||||||||||||||
| 43 | default => { | ||||||||||||||||||||
| 44 | restart => 0, | ||||||||||||||||||||
| 45 | wait => 0, | ||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||
| 47 | editor => { | ||||||||||||||||||||
| 48 | files => { | ||||||||||||||||||||
| 49 | eg => [qw/some-file.eg/], | ||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||
| 52 | terminals => { | ||||||||||||||||||||
| 53 | 0 | map { $_ => [] } 2 .. $count | |||||||||||||||||||
| 54 | }, | ||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | $self->hooks->run('init_config', $config); | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | if ( -f $file ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | ▶ | if ( ! $self->defaults->{force} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | die "The config file '.vtide.yml' already exists wont overwrite without --force!\n"; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 0 | warn "Overwritting '.vtide.yml'\n"; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | my $yaml = Dump( $config ); | |||||||||||||||||||
| 67 | 0 | my $now = localtime; | |||||||||||||||||||
| 68 | 0 | $yaml =~ s/^(---\s*\n)/$1# Create by App::VTide::Command::Init $now VERSION $App::VTide::Command::Init::VERSION\n/xms; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | $file->spew($yaml); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | $self->save_session( $name, $dir ); | |||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | return; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub auto_complete { | ||||||||||||||||||
|
Subroutine
auto_complete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 78 | 0 | return; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||