blib/lib/MYDan/VSSH.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 11 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 82 CC 7 SCAR 25.9
CC
7
Cov
0%
_comp
30.0
run
12.0
new
2.0
CRAP 13.3
1 package MYDan::VSSH;
2  
3 use strict;
4 use warnings;
5 use MYDan::VSSH::Execute;
6 use MYDan::VSSH::Comp;
7 use MYDan::VSSH::History;
8 use MYDan::VSSH::Print;
9  
10 $|++;
11  
12 our %RUN = ( max => 128, timeout => 300 );
13  
14 sub new
15 {
16 my ( $class, %self ) = @_;
17  
18 $self{config} = +{};
19  
20 bless \%self, ref $class || $class;
21 }
22  
23 sub run
24 {
25 my ( $this, %run, %busy ) = ( shift, %RUN, @_ );
26
27 my $history = MYDan::VSSH::History->new();
28 my $execute = MYDan::VSSH::Execute->new( node => $this->{node} );
29 my $print = MYDan::VSSH::Print->new();
30 $print->welcome();
31  
32 my $c = scalar @{$this->{node}};
33 while ( 1 )
34 {
35 next unless my $cmd = $this->_comp( $c, @run{qw( user sudo )} );
36 exit if $cmd eq 'exit' || $cmd eq 'quit' || $cmd eq 'logout';
37
38 my %result = $execute->run( %run, cmd => $cmd );
39 $print->result( %result );
40  
41 $history->push( $cmd );
42 }
43 }
44  
45 sub _comp
46 {
47 my ( $self, $c ) = splice @_, 0, 2;
48 my $tc = MYDan::VSSH::Comp->new(
49 'clear' => qr/\cl/,
50 'reverse' => qr/\cr/,
51 'wipe' => qr/\cw/,
52 prompt => sprintf( "%s ($c)sh#", join( ':', grep{$_}@_)|| 'mydan' ),
53 choices => [ ],
54 up => qr/\x1b\[[A]/,
55 down => qr/\x1b\[[B]/,
56 left => qr/\x1b\[[D]/,
57 right => qr/\x1b\[[C]/,
58 quit => qr/[\cc]/,
59 );
60 my ( $cmd, $danger ) = $tc->complete();
61 return $cmd unless $danger;
62 while( 1 )
63 {
64 print "$cmd [y/n]:";
65 my $in = <STDIN>;
66 next unless $in;
67 return $cmd if $in eq "y\n";
68 return undef if $in eq "n\n";
69 }
70 }
71  
72 1;