| 1 | package App::VTide::Command::Edit; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Created on: 2016-02-05 10:11:54 | ||||||||||||||||||||||||||||
| 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 Data::Dumper qw/Dumper/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use App::VTide::Sessions; | ||||||||||||||||||||||||||
|
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 = 'edit'; | |||||||||||||||||||||||||||
| 22 | 1 | our $OPTIONS = | |||||||||||||||||||||||||||
| 23 | [ 'add|add-to-session|a', 'recurse|r!', 'test|T!', 'save|s=s', 'verbose|v+', | ||||||||||||||||||||||||||||
| 24 | ]; | ||||||||||||||||||||||||||||
| 25 | 1 | our $LOCAL = 1; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub details_sub { return ( $NAME, $OPTIONS, $LOCAL ) } | ||||||||||||||||||||||||||
|
Subroutine
details_sub: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | has sessions => ( | ||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | lazy => 1, | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | App::VTide::Sessions->new(); | |||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | 1 | ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my ($name) = $self->env; | |||||||||||||||||||||||||||
| 40 | 0 | my $cmd = $self->options->files->[0]; | |||||||||||||||||||||||||||
| 41 | 0 | print "Running $name - $cmd\n"; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( $self->defaults->{add} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $self->sessions->add_session( @{ $self->options->files } ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $params = $self->params($cmd); | |||||||||||||||||||||||||||
| 48 | 0 | $params->{edit} = $self->options->files; | |||||||||||||||||||||||||||
| 49 | 0 | $params->{title} = $cmd; | |||||||||||||||||||||||||||
| 50 | 0 | $self->base($CWD); | |||||||||||||||||||||||||||
| 51 | 0 | my @cmd = $self->command( $params, $self->defaults->{recurse} ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( $params->{env} && ref $params->{env} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params->{"env"} and ref $params->{"env"} eq "HASH"
MC/DC0%0/2
$params->{"env"} and ref $params->{"env"} eq "HASH"
$params->{"env"}
ref $params->{"env"} eq "HASH"
Truth table0%0/3
A and B
A= $params->{"env"}B= ref $params->{"env"} eq "HASH"
| |||||||||||||||||||||||||||||
| 54 | 0 | for my $env ( keys %{ $params->{env} } ) { | |||||||||||||||||||||||||||
| 55 | 0 | my $orig = $ENV{$env}; | |||||||||||||||||||||||||||
| 56 | 0 | $ENV{$env} = $params->{env}{$env}; | |||||||||||||||||||||||||||
| 57 | 0 | $ENV{$env} =~ s/[\$]$env/$orig/xms; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | $self->load_env( $params->{env} ); | |||||||||||||||||||||||||||
| 62 | 0 | $self->hooks->run( 'edit_editing', \@cmd ); | |||||||||||||||||||||||||||
| 63 | 0 | $self->runit(@cmd); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $params = $self->params( $ENV{VTIDE_TERM} || '1' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'VTIDE_TERM'} || '1'
MC/DC0%0/1
$ENV{'VTIDE_TERM'} || '1'
$ENV{'VTIDE_TERM'}
Truth table0%0/2
A
A= $ENV{'VTIDE_TERM'}
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $title = $params->{title} || 'bash'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$params->{'title'} || 'bash'
MC/DC0%0/1
$params->{'title'} || 'bash'
$params->{'title'}
Truth table0%0/2
A
A= $params->{'title'}
| |||||||||||||||||||||||||||||
| 68 | 0 | my $max = 15; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( length $title > $max ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $title = substr $title, ( length $title ) - $max, $max + 1; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | eval { require Term::Title; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | and Term::Title::set_titlebar($title); | ||||||||||||||||||||||||||||
| 75 | 0 | system 'tmux', 'rename-window', $title; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | return; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub auto_complete { | ||||||||||||||||||||||||||
|
Subroutine
auto_complete: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $auto ) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $env = $self->options->files->[-1] // ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->options->files->[-1] // ""
MC/DC0%0/1
$self->options->files->[-1] // ""
$self->options->files->[-1]
Truth table0%0/2
A
A= $self->options->files->[-1]
| |||||||||||||||||||||||||||||
| 84 | 0 | my @files = sort keys %{ $self->config->get->{editor}{files} }; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | eval { | ||||||||||||||||||||||||||||
| 87 | 0 | my $helper = $self->config->get->{editor}{helper_autocomplete}; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($helper) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | my $helper_sub = eval $helper; ## no critic | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($helper_sub) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 91 | 0 | push @files, $helper_sub->( $auto, $self->options->files ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | elsif ($@) { | ||||||||||||||||||||||||||||
| 94 | 0 | warn "Errored parsing '$@':\n$helper\n"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||
| 97 | 0 | warn "Unknown error with helper sub\n"; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | 1; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | } or do { warn $@ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | print join ' ', | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | grep { $env ne 'vtide' && $env ne 'edit' ? /^$env/xms : 1 } @files; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$env ne "vtide" and $env ne "edit"
MC/DC0%0/2
$env ne "vtide" and $env ne "edit"
$env ne "vtide"
$env ne "edit"
Truth table0%0/3
A and B
A= $env ne "vtide"B= $env ne "edit"
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||