blib/lib/Net/Appliance/Session/Transport.pm

filter: Statementstmt 30.7% 16 / 52 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 60.0% 3 / 5 Podpod 0.0% 0 / 2 totaltotal 15.4% 19 / 123 SCAR 60.0
CC
25
Cov
15%
connect
306.0
close
90.0
BEGIN
1.0
CRAP 403.6
« blib/lib/Net/Appliance/Session/Engine.pm ↑ Summary blib/lib/Net/Appliance/Session/Async.pm »
1 package Net::Appliance::Session::Transport;
2 1 { $Net::Appliance::Session::Transport::VERSION = '4.300003' }
3  
4 {
5 1 package # hide from pause
6 Net::Appliance::Session::Transport::ConnectOptions;
7 1 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use MooX::Types::MooseLike::Base qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 has username => (
11 is => 'ro',
12 isa => Str,
13 required => 0,
14 predicate => 1,
15 );
16  
17 1 has password => (
18 is => 'ro',
19 isa => Str,
20 required => 0,
21 predicate => 1,
22 );
23  
24 1 has privileged_password => (
25 is => 'ro',
26 isa => Str,
27 required => 0,
28 predicate => 1,
29 );
30 }
31  
32 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 sub connect {
35 0 ▶ my $self = shift;
Subroutine connect: not called CC=17 SCAR=57.2
Pod undocumented
36 0 my $options = Net::Appliance::Session::Transport::ConnectOptions->new(@_);
37  
38 0 foreach my $slot (qw/ username password privileged_password /) {
39 0 my $has = 'has_' . $slot;
40 0 my $set = 'set_' . $slot;
41 0 ▶ $self->$set($options->$slot) if $options->$has;
Branch: 1 branch
BranchTrueFalseTotal
if $options->$has 0 0 0
42 }
43  
44 0 ▶ if ($self->nci->transport->is_win32 and $self->has_password) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nci->transport->is_win32 and $self->has_password) 0 0 0
Condition0%0/3
$self->nci->transport->is_win32 and $self->has_password
!ll&&!rl&&r
000
MC/DC0%0/2
$self->nci->transport->is_win32 and $self->has_password
$self->nci->transport->is_win32 $self->has_password
Truth table0%0/3
A and B
A= $self->nci->transport->is_win32B= $self->has_password
ABresult
0X0
100
111
45 0 $self->set_password($self->get_password . $self->nci->transport->ors);
46 }
47  
48 # SSH transport takes a username if we have one
49 0 ▶ $self->nci->transport->connect_options->username($self->get_username)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_username and $self->nci->transport->connect_options->can("username") 0 0 0
Condition0%0/3
$self->has_username and $self->nci->transport->connect_options->can("username")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_username and $self->nci->transport->connect_options->can("username")
$self->has_username $self->nci->transport->connect_options->can("username")
Truth table0%0/3
A and B
A= $self->has_usernameB= $self->nci->transport->connect_options->can("username")
ABresult
0X0
100
111
50 if $self->has_username
51 and $self->nci->transport->connect_options->can('username');
52  
53 # poke remote device (whether logging in or not)
54 0 $self->find_prompt($self->wake_up);
55  
56 # optionally, log in to the remote host
57 0 ▶ if ($self->do_login and not $self->prompt_looks_like('generic')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_login and not $self->prompt_looks_like("generic")) 0 0 0
Condition0%0/3
$self->do_login and not $self->prompt_looks_like("generic")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->do_login and not $self->prompt_looks_like("generic")
$self->do_login not $self->prompt_looks_like("generic")
Truth table0%0/3
A and not(B)
A= $self->do_loginB= not $self->prompt_looks_like("generic")
ABresult
0X0
100
111
58  
59 0 ▶ if ($self->nci->phrasebook->has_prompt('user')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nci->phrasebook->has_prompt("user") and $self->prompt_looks_like("user")) 0 0 0
Condition0%0/3
$self->nci->phrasebook->has_prompt("user") and $self->prompt_looks_like("user")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->nci->phrasebook->has_prompt("user") and $self->prompt_looks_like("user")
$self->nci->phrasebook->has_prompt("user") $self->prompt_looks_like("user")
Truth table0%0/3
A and B
A= $self->nci->phrasebook->has_prompt("user")B= $self->prompt_looks_like("user")
ABresult
0X0
100
111
60 and $self->prompt_looks_like('user')) {
61 0 ▶ die 'a set username is required to connect to this host'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_username 0 0 0
62 if not $self->has_username;
63  
64 0 $self->cmd($self->get_username, { match => 'pass' });
65 }
66  
67 0 ▶ die 'a set password is required to connect to this host'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_password 0 0 0
68 if not $self->has_password;
69  
70 # support for serial console servers where, after loggin in to the
71 # server, the console is asleep and needs waking up to show its prompt
72 0 $self->say($self->get_password);
73 0 $self->find_prompt($self->wake_up);
74 }
75  
76 0 ▶ $self->prompt_looks_like('generic')
Branch: 1 branch
BranchTrueFalseTotal
$self->prompt_looks_like("generic") or die "login failed to remote host - prompt does not match" 0 0 0
77 or die 'login failed to remote host - prompt does not match';
78  
79 0 $self->close_called(0);
80 0 $self->logged_in(1);
81  
82 0 ▶ $self->in_privileged_mode( $self->do_privileged_mode ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$self->do_privileged_mode ? : 0 0 0
83 0 ▶ $self->in_configure_mode( $self->do_configure_mode ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$self->do_configure_mode ? : 0 0 0
84  
85 # disable paging... this is undone in our close() method
86 0 ▶ $self->disable_paging if $self->do_paging;
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_paging 0 0 0
87  
88 0 return $self;
89 }
90  
91 sub close {
92 0 ▶ my $self = shift;
Subroutine close: not called CC=9 SCAR=45.0
Pod undocumented
93  
94 # protect against death spiral (rt.cpan #53796)
95 0 ▶ return if $self->close_called;
Branch: 1 branch
BranchTrueFalseTotal
if $self->close_called 0 0 0
96 0 $self->close_called(1);
97  
98 0 ▶ if ($self->nci->transport->connect_ready) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nci->transport->connect_ready) 0 0 0
99 0 ▶ $self->end_configure
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_configure_mode and $self->in_configure_mode 0 0 0
Condition0%0/3
$self->do_configure_mode and $self->in_configure_mode
!ll&&!rl&&r
000
MC/DC0%0/2
$self->do_configure_mode and $self->in_configure_mode
$self->do_configure_mode $self->in_configure_mode
Truth table0%0/3
A and B
A= $self->do_configure_modeB= $self->in_configure_mode
ABresult
0X0
100
111
100 if $self->do_configure_mode and $self->in_configure_mode;
101 0 ▶ $self->end_privileged
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_privileged_mode and $self->in_privileged_mode 0 0 0
Condition0%0/3
$self->do_privileged_mode and $self->in_privileged_mode
!ll&&!rl&&r
000
MC/DC0%0/2
$self->do_privileged_mode and $self->in_privileged_mode
$self->do_privileged_mode $self->in_privileged_mode
Truth table0%0/3
A and B
A= $self->do_privileged_modeB= $self->in_privileged_mode
ABresult
0X0
100
111
102 if $self->do_privileged_mode and $self->in_privileged_mode;
103  
104 # re-enable paging
105 0 ▶ $self->enable_paging if $self->do_paging;
Branch: 1 branch
BranchTrueFalseTotal
if $self->do_paging 0 0 0
106  
107 # issue disconnect macro if the phrasebook has one
108 0 ▶ if ($self->nci->phrasebook->has_macro('disconnect')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nci->phrasebook->has_macro("disconnect")) 0 0 0
109 0 eval { $self->macro('disconnect') };
110 # this should die as there's no returned prompt (NCI pump() fails)
111 }
112  
113 0 $self->nci->transport->disconnect;
114 # there is no longer a transport
115 }
116  
117 0 $self->logged_in(0);
118 }
119  
120 1 1;
« blib/lib/Net/Appliance/Session/Engine.pm ↑ Summary blib/lib/Net/Appliance/Session/Async.pm »