VTide/Command/Conf.pm

filter: Statementstmt 28.5% 26 / 91 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 58.3% 7 / 12 Podpod 100% 4 / 4 totaltotal 25.6% 37 / 144 CC 22 SCAR 45.1
CC
22
Cov
21%
run
156.0
which
110.0
auto_complete
6.0
CRAP 90.8
« VTide/Command/Run.pm ↑ Summary VTide/Command/Help.pm »
1 package App::VTide::Command::Conf;
2  
3 # Created on: 2016-02-08 10:42:09
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 YAML::Syck qw/ Dump /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Array::Utils qw/intersect/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 extends 'App::VTide::Command';
18  
19 1 our $VERSION = version->new('1.0.6');
20 1 our $NAME = 'conf';
21 1 our $OPTIONS = [ 'env|e', 'terms|t', 'which|w=s', 'test|T!', 'verbose|v+', ];
22 0 ▶sub details_sub { return ( $NAME, $OPTIONS ) }
Subroutine details_sub: not called CC=1 SCAR=6.9
Pod documented
23  
24 0 ▶sub _alphanum {
Subroutine _alphanum: not called CC=1 SCAR=6.9
25 0 my $A = $a;
26 0 my $B = $b;
27 0 $A =~ s/(\d+)/sprintf "%05i", $1/egxms;
28 0 $B =~ s/(\d+)/sprintf "%05i", $1/egxms;
29 0 return $A cmp $B;
30 }
31  
32 0 ▶sub run {
Subroutine run: not called CC=12 SCAR=50.5
Pod documented
33 0 my ($self) = @_;
34  
35 0 ▶ if ( $self->defaults->{env} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{"env"}) 0 0 0
36 my %env = (
37 0 ▶ %{ $self->config->get->{default}{env} || {} },
Condition0%0/2
$self->config->get->{'default'}{'env'} || {}
l!l
00
MC/DC0%0/1
$self->config->get->{'default'}{'env'} || {}
$self->config->get->{'default'}{'env'}
Truth table0%0/2
A
A= $self->config->get->{'default'}{'env'}
Aresult
11
00
38 %{
39 0 $self->config->get->{terminals}{ $ENV{VTIDE_TERM} }{env} || {}
40 0 ▶ }
Condition0%0/2
$self->config->get->{'terminals'}{$ENV{'VTIDE_TERM'}}{'env'} || {}
l!l
00
MC/DC0%0/1
$self->config->get->{'terminals'}{$ENV{'VTIDE_TERM'}}{'env'} || {}
$self->config->get->{'terminals'}{$ENV{'VTIDE_TERM'}}{'env'}
Truth table0%0/2
A
A= $self->config->get->{'terminals'}{$ENV{'VTIDE_TERM'}}{'env'}
Aresult
11
00
41 );
42 0 for my $env ( sort keys %ENV ) {
43 0 ▶ next if $env !~ /VTIDE/ && !exists $env{$env};
Branch: 1 branch
BranchTrueFalseTotal
unless $env =~ /VTIDE/ or exists $env{$env} 0 0 0
Condition0%0/3
$env =~ /VTIDE/ or exists $env{$env}
l!l&&r!l&&!r
000
MC/DC0%0/2
$env =~ /VTIDE/ or exists $env{$env}
$env =~ /VTIDE/ exists $env{$env}
Truth table0%0/3
A or B
A= $env =~ /VTIDE/B= exists $env{$env}
ABresult
1X1
011
000
44 0 printf "%-12s : %s\n", $env, $ENV{$env};
45 }
46 0 print "\n";
47 }
48  
49 0 ▶ if ( $self->defaults->{which} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{"which"}) 0 0 0
50 0 return $self->which( $self->defaults->{which} );
51 }
52  
53 my $data =
54 $self->defaults->{terms}
55 ? $self->config->get->{terminals}
56 0 ▶ : $self->config->get->{editor}{files};
Branch: 1 branch
BranchTrueFalseTotal
$self->defaults->{'terms'} ? : 0 0 0
57 0 my @files = sort _alphanum keys %{$data};
58  
59 print $self->defaults->{terms}
60 0 ▶ ? "Terminals configured:\n"
Branch: 1 branch
BranchTrueFalseTotal
$self->defaults->{'terms'} ? : 0 0 0
61 : "File groups:\n";
62 0 ▶ if ( $self->defaults->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{'verbose'}) { } 0 0 0
63 0 for my $file (@files) {
64 0 my $data = Dump( $data->{$file} );
65 0 $data =~ s/^---//xms;
66 0 print $file, $data, "\n";
67 }
68 }
69 else {
70 0 print join "\n", @files, '';
71 }
72  
73 0 return;
74 }
75  
76 0 ▶sub which {
Subroutine which: not called CC=10 SCAR=47.0
Pod documented
77 0 my ( $self, $which ) = @_;
78 0 my $term = $self->config->get->{terminals};
79 0 my $file = $self->config->get->{editor}{files};
80 0 my ( %files, %groups, %terms );
81  
82 0 for my $group ( keys %$file ) {
83 0 my @found = grep { /$which/ }
84 0 @{ $file->{$group} },
85 0 map { $self->_dglob($_) } @{ $file->{$group} };
86 0 ▶ next if !@found;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 0 0 0
87  
88 0 for my $found (@found) {
89 0 $files{$found}++;
90 }
91 0 $groups{$group}++;
92 }
93  
94 0 my @files = sort keys %files;
95 0 my @groups = sort keys %groups;
96 0 my @terms;
97 0 for my $terminal ( sort keys %$term ) {
98 my $edit =
99 !$term->{$terminal}{edit} ? []
100 : !ref $term->{$terminal}{edit} ? [ $term->{$terminal}{edit} ]
101 0 ▶ : $term->{$terminal}{edit};
Branch: 2 branches
BranchTrueFalseTotal
!$term->{$terminal}{'edit'} ? : 0 0 0
!ref($term->{$terminal}{'edit'}) ? : 0 0 0
102  
103 0 my @found =
104 ( ( intersect @files, @$edit ), ( intersect @groups, @$edit ), );
105 0 ▶ next if !@found;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 0 0 0
106 0 push @terms, $terminal;
107 }
108  
109 0 ▶ if (@files) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) { } 0 0 0
110 0 print "Files: " . ( join ', ', @files ) . "\n";
111 0 print "Groups: " . ( join ', ', @groups ) . "\n";
112 0 ▶ print "Terminals: " . ( join ', ', @terms ) . "\n" if @terms;
Branch: 1 branch
BranchTrueFalseTotal
if @terms 0 0 0
113 }
114 else {
115 0 print "Not found\n";
116 }
117  
118 0 return;
119 }
120  
121 0 ▶sub auto_complete {
Subroutine auto_complete: not called CC=2 SCAR=17.9
Pod documented
122 0 my ($self) = @_;
123  
124 0 my $env = $self->options->files->[-1];
125 0 my @files = sort keys %{ $self->config->get->{editor}{files} };
126  
127 0 ▶ print join ' ', grep { $env ne 'conf' ? /^$env/xms : 1 } @files;
Branch: 1 branch
BranchTrueFalseTotal
$env ne 'conf' ? : 0 0 0
128  
129 0 return;
130 }
131  
132 1 1;
133  
134 __END__
« VTide/Command/Run.pm ↑ Summary VTide/Command/Help.pm »