VTide/Command/Start.pm

filter: Statementstmt 30.8% 33 / 107 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 56.2% 9 / 16 Podpod 100% 6 / 6 totaltotal 22.4% 48 / 214 CC 36 SCAR 53.3
CC
36
Cov
19%
tmux_window
462.0
tmux
72.0
ctags
30.0
CRAP 206.1
« VTide/Command/History.pm ↑ Summary VTide/Command/Run.pm »
1 package App::VTide::Command::Start;
2  
3 # Created on: 2016-01-30 15:06:48
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 1 ▶use App::VTide::Sessions;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 extends 'App::VTide::Command';
20  
21 1 our $VERSION = version->new('1.0.6');
22 1 our $NAME = 'start';
23 1 our $OPTIONS =
24 [ 'windows|w=i', 'add|add-to-session|a', 'test|T!', 'verbose|v+', ];
25 0 ▶sub details_sub { return ( $NAME, $OPTIONS ) }
Subroutine details_sub: not called CC=1 SCAR=6.9
Pod documented
26  
27 has sessions => (
28 is => 'ro',
29 lazy => 1,
30 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 App::VTide::Sessions->new(
32 sessions_file => path $ENV{HOME},
33 0 '.vtide/sessions.yml'
34 );
35 },
36 1 );
37  
38 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
39 0 my ($self) = @_;
40  
41 0 my ( $name, $dir ) = $self->session_dir( $self->options->files->[0] );
42  
43 0 local $CWD = $dir;
44  
45 0 $self->save_session( $name, $dir );
46  
47 0 $self->hooks->run( 'start_pre', $name, $dir );
48  
49 0 $self->ctags();
50  
51 0 ▶ if ( $self->options->default->{add} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->default->{"add"}) 0 0 0
52 0 $self->sessions->add_session($name);
53 }
54  
55 0 ▶ return $self->tmux( $self->vtide->config->data->{title} || $name, $name );
Condition0%0/3
$self->vtide->config->data->{'title'} || $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->vtide->config->data->{'title'} || $name
$self->vtide->config->data->{'title'} $name
Truth table0%0/3
A || B
A= $self->vtide->config->data->{'title'}B= $name
ABresult
1X1
011
000
56 }
57  
58 0 ▶sub ctags {
Subroutine ctags: not called CC=5 SCAR=34.0
Pod documented
59 0 my ($self) = @_;
60 0 my $ctags = path( '/usr', 'bin', 'ctags' );
61  
62 0 ▶ return if !$self->config->get->{start}{ctags} || !-x $ctags;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->config->get->{"start"}{"ctags"} and -x $ctags 0 0 0
Condition0%0/3
$self->config->get->{"start"}{"ctags"} and -x $ctags
!ll&&!rl&&r
000
MC/DC0%0/2
$self->config->get->{"start"}{"ctags"} and -x $ctags
$self->config->get->{"start"}{"ctags"} -x $ctags
Truth table0%0/3
A and B
A= $self->config->get->{"start"}{"ctags"}B= -x $ctags
ABresult
0X0
100
111
63  
64 0 my @cmd = ( $ctags, $self->config->get->{start}{ctags} );
65  
66 0 for my $exclude ( @{ $self->config->get->{start}{"ctags-exclude"} } ) {
67 0 ▶ if ( $self->config->get->{start}{"ctags-excludes"}{$exclude} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->config->get->{'start'}{'ctags-excludes'}{$exclude}) { } 0 0 0
68 push @cmd,
69 0 map { "--exclude=$_" }
70 0 @{ $self->config->get->{start}{"ctags-excludes"}{$exclude} };
71 }
72 else {
73 0 push @cmd, "--exclude=$exclude";
74 }
75 }
76  
77 0 system @cmd;
78 }
79  
80 0 ▶sub tmux {
Subroutine tmux: not called CC=8 SCAR=42.8
Pod documented
81 0 my ( $self, $title, $name ) = @_;
82  
83 0 print "\033];$title\007";
84 0 ▶ eval { require Term::Title; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Term::Title } } and Term::Title::set_titlebar($title) 0 0 0
85 and Term::Title::set_titlebar($title);
86  
87 0 my %session = map { /(^[^:]+)/xms; $1 => 1 } `tmux ls`;
88 0 ▶ if ( $session{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session{$name}) 0 0 0
89  
90 # reconnect
91 0 exec 'tmux', 'attach-session', '-t', $name;
92 }
93  
94 0 ▶ my $v = $self->defaults->{verbose} ? '--verbose' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->defaults->{'verbose'} ? : 0 0 0
95 0 $v .= " --name $name";
96 0 my $tmux = 'tmux -u2 ';
97 0 ▶ my $count = $self->defaults->{windows} || $self->config->get->{count};
Condition0%0/3
$self->defaults->{'windows'} || $self->config->get->{'count'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->defaults->{'windows'} || $self->config->get->{'count'}
$self->defaults->{'windows'} $self->config->get->{'count'}
Truth table0%0/3
A || B
A= $self->defaults->{'windows'}B= $self->config->get->{'count'}
ABresult
1X1
011
000
98  
99 0 for my $window ( 1 .. $count ) {
100 0 $tmux .= $self->tmux_window( $window, "vtide run $v", $name );
101 }
102 0 $tmux .= "select-window -t 1";
103  
104 0 ▶ if ( $self->defaults->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{"test"}) 0 0 0
105 0 print "$tmux\n";
106 0 return 1;
107 }
108  
109 0 ▶ mkdir '.vtide' if !-d '.vtide';
Branch: 1 branch
BranchTrueFalseTotal
unless -d ".vtide" 0 0 0
110 0 my $fh = path( '.vtide', 'start.log' )->opena;
111 0 print {$fh} '[' . localtime . "] START TMUX $tmux\n";
112  
113 0 system $tmux;
114  
115 0 print {$fh} '[' . localtime . "] END TMUX $tmux\n";
116 }
117  
118 0 ▶sub tmux_window {
Subroutine tmux_window: not called CC=21 SCAR=61.4
Pod documented
119 0 my ( $self, $term, $cmd, $name, $split ) = @_;
120 0 ▶ my $conf = !$term ? {} : $self->config->get->{terminals}{$term};
Branch: 1 branch
BranchTrueFalseTotal
!$term ? : 0 0 0
121 0 ▶ my $out =
Branch: 2 branches
BranchTrueFalseTotal
$split ? : 0 0 0
$term == 1 ? : 0 0 0
122 $split ? ''
123 : $term == 1 ? "new-session -s $name '$cmd $term' \\; "
124 : "new-window '$cmd $term' \\; ";
125 0 ▶ my $letter = !$term ? '' : 'a';
Branch: 1 branch
BranchTrueFalseTotal
!$term ? : 0 0 0
126  
127 0 ▶ if ( !$conf || ref $conf ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $conf or ref $conf ne "HASH") 0 0 0
Condition0%0/3
not $conf or ref $conf ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $conf or ref $conf ne "HASH"
not $conf ref $conf ne "HASH"
Truth table0%0/3
not(A) or B
A= not $confB= ref $conf ne "HASH"
ABresult
1X1
011
000
128 0 $conf = {};
129 }
130  
131 0 ▶ $term ||= '';
Condition0%0/2
$term ||= ""
l!l
00
MC/DC0%0/1
$term ||= ""
$term
Truth table0%0/2
A
A= $term
Aresult
11
00
132 0 ▶ $split ||= $conf->{split};
Condition0%0/3
$split ||= $conf->{"split"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$split ||= $conf->{"split"}
$split $conf->{"split"}
Truth table0%0/3
A ||= B
A= $splitB= $conf->{"split"}
ABresult
1X1
011
000
133  
134 0 ▶ for my $split ( split //xms, ( $split || '' ) ) {
Condition0%0/2
$split || ''
l!l
00
MC/DC0%0/1
$split || ''
$split
Truth table0%0/2
A
A= $split
Aresult
11
00
135 0 ▶ next if !defined $split || $split eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $split or $split eq "" 0 0 0
Condition0%0/3
not defined $split or $split eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $split or $split eq ""
not defined $split $split eq ""
Truth table0%0/3
not(A) or B
A= not defined $splitB= $split eq ""
ABresult
1X1
011
000
136  
137 0 ▶ my $arg =
Branch: 5 branches
BranchTrueFalseTotal
$split eq 'H' ? : 0 0 0
$split eq 'h' ? : 0 0 0
$split eq 'V' ? : 0 0 0
$split eq 'v' ? : 0 0 0
$split =~ /^\d$/x ? : 0 0 0
138 $split eq 'H' ? 'split-window -h'
139 : $split eq 'h' ? 'split-window -dh'
140 : $split eq 'V' ? 'split-window -v'
141 : $split eq 'v' ? 'split-window -dv'
142 : $split =~ /^\d$/x ? 'select-pane -t ' . $split
143 : die "Unknown split for terminal $term $split (split = '$split')!\n";
144  
145 0 ▶ $out .=
Branch: 1 branch
BranchTrueFalseTotal
$split =~ /^\d$/msx ? : 0 0 0
146 $split =~ /^\d$/xms ? "$arg \\; " : "$arg '$cmd $term$letter' \\; ";
147 0 ▶ $letter++ if $letter;
Branch: 1 branch
BranchTrueFalseTotal
if $letter 0 0 0
148 }
149  
150 0 ▶ if ( $conf->{tmux} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"tmux"}) 0 0 0
151 0 $out .= "$conf->{tmux} \\; ";
152 }
153  
154 0 return $out;
155 }
156  
157 0 ▶sub auto_complete {
Subroutine auto_complete: not called CC=3 SCAR=24.8
Pod documented
158 0 my ($self) = @_;
159  
160 0 my $file = $self->history;
161 0 ▶ my $sessions = eval { LoadFile($file) } || {};
Condition0%0/2
eval { do { LoadFile($file) } } || {}
l!l
00
MC/DC0%0/1
eval { do { LoadFile($file) } } || {}
eval { do { LoadFile($file) } }
Truth table0%0/2
A
A= eval { do { LoadFile($file) } }
Aresult
11
00
162  
163 0 my $env = $self->options->files->[-1];
164 0 ▶ print join ' ', grep { $env ne 'start' ? /^$env/xms : 1 }
Branch: 1 branch
BranchTrueFalseTotal
$env ne 'start' ? : 0 0 0
165 0 sort keys %{ $sessions->{sessions} };
166  
167 0 return;
168 }
169  
170 1 1;
171  
172 __END__
« VTide/Command/History.pm ↑ Summary VTide/Command/Run.pm »