| 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
| |||||||||||||||||||||||||||||
| 36 | my %env = ( | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | %{ $self->config->get->{default}{env} || {} }, | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->config->get->{'default'}{'env'} || {}
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'}
| |||||||||||||||||||||||||||||
| 38 | %{ | ||||||||||||||||||||||||||||
| 39 | 0 | $self->config->get->{terminals}{ $ENV{VTIDE_TERM} }{env} || {} | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | } | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->config->get->{'terminals'}{$ENV{'VTIDE_TERM'}}{'env'} || {}
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'}
| |||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | 0 | for my $env ( sort keys %ENV ) { | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | next if $env !~ /VTIDE/ && !exists $env{$env}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$env =~ /VTIDE/ or exists $env{$env}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | 0 | my @files = sort _alphanum keys %{$data}; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | print $self->defaults->{terms} | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | ? "Terminals configured:\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | : "File groups:\n"; | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( $self->defaults->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my @found = | |||||||||||||||||||||||||||
| 104 | ( ( intersect @files, @$edit ), ( intersect @groups, @$edit ), ); | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | next if !@found; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | push @terms, $terminal; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (@files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 1 | 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||