VTide/Command/Save.pm

filter: Statementstmt 41.6% 30 / 72 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 57.1% 8 / 14 Podpod 100% 6 / 6 totaltotal 34.3% 44 / 128 CC 16 SCAR 33.5
CC
16
Cov
30%
diff_env
72.0
save_env
30.0
run
20.0
CRAP 28.6
« VTide/Command/Grep.pm ↑ Summary VTide/Command/Refresh.pm »
1 package App::VTide::Command::Save;
2  
3 # Created on: 2016-01-30 20:38:50
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 List::MoreUtils qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 extends 'App::VTide::Command::Run';
19  
20 1 our $VERSION = version->new('1.0.6');
21 1 our $NAME = 'save';
22 1 our $OPTIONS = [
23 'name|n=s',
24 'record_env|record-env|r',
25 'diff_env|diff-env|d',
26 'save_env|save-env|s',
27 'test|T!',
28 'verbose|v+',
29 ];
30 0 ▶sub details_sub { return ( $NAME, $OPTIONS )};
Subroutine details_sub: not called CC=1 SCAR=6.9
Pod documented
31  
32 1 has env_store => (
33 is => 'ro',
34 default => '.vtide/.current-env',
35 );
36  
37 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
38 0 my ($self) = @_;
39  
40 0 ▶ if ( $self->defaults->{record_env} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->defaults->{'record_env'}) { } 0 0 0
elsif ($self->defaults->{'diff_env'}) { } 0 0 0
elsif ($self->defaults->{'save_env'}) { } 0 0 0
41 0 $self->record_env();
42 0 $self->hooks->run('save_record_env');
43 }
44 elsif ( $self->defaults->{diff_env} ) {
45 0 $self->defaults->{verbose} = 1;
46 0 $self->diff_env();
47 }
48 elsif ( $self->defaults->{save_env} ) {
49 0 $self->save_env( $self->diff_env() );
50 0 $self->hooks->run( 'save_save_env', $self->diff_env() );
51 }
52 else {
53 # default name is the project name
54 0 $self->save( $self->defaults->{name}, @ARGV );
55 }
56  
57 0 return;
58 }
59  
60 0 ▶sub save {
Subroutine save: not called CC=2 SCAR=17.9
Pod documented
61 0 my ($self, $name, @files) = @_;
62  
63 0 ▶ my $file = $ENV{VTIDE_CONFIG} || '.vtide.yml';
Condition0%0/2
$ENV{'VTIDE_CONFIG'} || '.vtide.yml'
l!l
00
MC/DC0%0/1
$ENV{'VTIDE_CONFIG'} || '.vtide.yml'
$ENV{'VTIDE_CONFIG'}
Truth table0%0/2
A
A= $ENV{'VTIDE_CONFIG'}
Aresult
11
00
64 0 my $config = LoadFile($file);
65  
66 0 $config->{editor}{files}{$name} = [ @files ];
67  
68 0 DumpFile($file, $config);
69  
70 0 return;
71 }
72  
73 0 ▶sub record_env {
Subroutine record_env: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($self) = @_;
75  
76 0 path($self->env_store)->parent->mkpath;
77  
78 0 DumpFile($self->env_store, \%ENV);
79  
80 0 return;
81 }
82  
83 0 ▶sub diff_env {
Subroutine diff_env: not called CC=8 SCAR=42.8
Pod documented
84 0 my ($self) = @_;
85  
86 0 my $old_env = LoadFile($self->env_store);
87 0 my @keys = uniq sort keys %ENV, keys %$old_env;
88 0 my %diff;
89  
90 0 for my $key (@keys) {
91 0 ▶ next if ($ENV{$key} || '') eq ($old_env->{$key} || '');
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$key} || "") eq ($old_env->{$key} || "") 0 0 0
Condition0%0/4
$ENV{$key} || ''
l!l
00
$old_env->{$key} || ''
l!l
00
MC/DC0%0/1
$ENV{$key} || ''
$ENV{$key}
MC/DC0%0/1
$old_env->{$key} || ''
$old_env->{$key}
Truth table0%0/2
A
A= $ENV{$key}
Aresult
11
00
Truth table0%0/2
A
A= $old_env->{$key}
Aresult
11
00
92 0 ▶ if ( $self->defaults->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{"verbose"}) 0 0 0
93 0 ▶ printf "%-15s %-45.45s %-45.45s\n", $key, $ENV{$key} || q{''}, $old_env->{$key} || q{''};
Condition0%0/4
$ENV{$key} || q['']
l!l
00
$old_env->{$key} || q['']
l!l
00
MC/DC0%0/1
$ENV{$key} || q['']
$ENV{$key}
MC/DC0%0/1
$old_env->{$key} || q['']
$old_env->{$key}
Truth table0%0/2
A
A= $ENV{$key}
Aresult
11
00
Truth table0%0/2
A
A= $old_env->{$key}
Aresult
11
00
94 }
95 0 $diff{$key} = $ENV{$key};
96 }
97  
98 0 return %diff;
99 }
100  
101 0 ▶sub save_env {
Subroutine save_env: not called CC=5 SCAR=34.0
Pod documented
102 0 my ($self, %env) = @_;
103  
104 0 ▶ my $file = $ENV{VTIDE_CONFIG} || '.vtide.yml';
Condition0%0/2
$ENV{'VTIDE_CONFIG'} || '.vtide.yml'
l!l
00
MC/DC0%0/1
$ENV{'VTIDE_CONFIG'} || '.vtide.yml'
$ENV{'VTIDE_CONFIG'}
Truth table0%0/2
A
A= $ENV{'VTIDE_CONFIG'}
Aresult
11
00
105 0 my $config = LoadFile($file);
106  
107 0 ▶ if ( $self->defaults->{terminal} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{'terminal'}) { } 0 0 0
108 0 my $term = $self->defaults->{terminal};
109 $config->{terminals}{$term}{env} = {
110 0 ▶ %{ $config->{terminals}{$term}{env} || {} },
Condition0%0/2
$config->{'terminals'}{$term}{'env'} || {}
l!l
00
MC/DC0%0/1
$config->{'terminals'}{$term}{'env'} || {}
$config->{'terminals'}{$term}{'env'}
Truth table0%0/2
A
A= $config->{'terminals'}{$term}{'env'}
Aresult
11
00
111 %env,
112 };
113 }
114 else {
115 $config->{default}{env} = {
116 0 ▶ %{ $config->{default}{env} || {} },
Condition0%0/2
$config->{'default'}{'env'} || {}
l!l
00
MC/DC0%0/1
$config->{'default'}{'env'} || {}
$config->{'default'}{'env'}
Truth table0%0/2
A
A= $config->{'default'}{'env'}
Aresult
11
00
117 %env,
118 };
119 }
120  
121 0 DumpFile($file, $config);
122  
123 0 return;
124 }
125  
126 1 1;
127  
128 __END__
« VTide/Command/Grep.pm ↑ Summary VTide/Command/Refresh.pm »