blib/lib/MYDan/VSSH.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 92 CC 8 SCAR 27.2
CC
8
Cov
0%
_comp
30.0
run
20.0
new
2.0
CRAP 15.2
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 $audit = $run{audit};
33 my $c = scalar @{$this->{node}};
34 while ( 1 )
35 {
36 next unless my $cmd = $this->_comp( $c, @run{qw( user sudo )} );
37 exit if $cmd eq 'exit' || $cmd eq 'quit' || $cmd eq 'logout';
38
39 &$audit( $cmd ) if $audit;
40  
41 my %result = $execute->run( %run, cmd => $cmd );
42 $print->result( %result );
43  
44 $history->push( $cmd );
45 }
46 }
47  
48 sub _comp
49 {
50 my ( $self, $c ) = splice @_, 0, 2;
51 my $tc = MYDan::VSSH::Comp->new(
52 'clear' => qr/\cl/,
53 'reverse' => qr/\cr/,
54 'wipe' => qr/\cw/,
55 prompt => sprintf( "%s ($c)sh#", join( ':', grep{$_}@_)|| 'mydan' ),
56 choices => [ ],
57 up => qr/\x1b\[[A]/,
58 down => qr/\x1b\[[B]/,
59 left => qr/\x1b\[[D]/,
60 right => qr/\x1b\[[C]/,
61 quit => qr/[\cc]/,
62 );
63 my ( $cmd, $danger ) = $tc->complete();
64 return $cmd unless $danger;
65 while( 1 )
66 {
67 print "$cmd [y/n]:";
68 my $in = <STDIN>;
69 next unless $in;
70 return $cmd if $in eq "y\n";
71 return undef if $in eq "n\n";
72 }
73 }
74  
75 1;