| 1 | package Net::Telnet::Cisco; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Net::Telnet::Cisco - interact with a Cisco router | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # $Id: Cisco.pm,v 1.52 2002/06/18 17:17:03 jkeroes Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Todo: Add error and access logging. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # POD documentation at end of file. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | #----------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | require 5.005; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Net::Telnet 3.02; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use AutoLoader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use vars qw($AUTOLOAD @ISA $VERSION $DEBUG); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | @ISA = qw(Net::Telnet); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | $VERSION = '1.12'; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | $^W = 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | $|++; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # Public Methods | ||||||||||||||||||||||||||||||||||||||||||
| 32 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=21 SCAR=61.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my ($self, $host, %args); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my %ntparams = ( | |||||||||||||||||||||||||||||||||||||||||
| 41 | prompt => '/(?m:^(?:[\w.\/]+\:)?[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/' | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my %params = ( | |||||||||||||||||||||||||||||||||||||||||
| 44 | always_waitfor_prompt => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | autopage => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | ignore_warnings => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | last_cmd => '', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | last_prompt => '', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | more_prompt => '/(?m:^\s*--More--)/', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | normalize_cmd => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | send_wakeup => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | waitfor_pause => 0.1, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | warnings => '/(?mx:^% Unknown VPN | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |^%IP routing table VRF.* does not exist. Create first$ | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |^%No CEF interface information | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |^%No matching route to delete$ | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |^%Not all config may be removed and may reappear after reactivating | ||||||||||||||||||||||||||||||||||||||||||
| 58 | )/', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | ## Parse the args. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (@_ == 1) { # one positional arg given | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ($ntparams{host}) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | ## initial set other named args. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | foreach (keys %args) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (/^-?always_waitfor_prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $params{always_waitfor_prompt} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | elsif (/^-?autopage$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $params{autopage} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | elsif (/^-?ignore_warnings$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $params{ignore_warnings} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif (/^-?more_prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $params{more_prompt} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif (/^-?normalize_cmd$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $params{normalize_cmd} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | elsif (/^-?send_wakeup$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $params{send_wakeup} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | elsif (/^-?waitfor_pause$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $params{waitfor_pause} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | elsif (/^-?warnings$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $params{warnings} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | elsif (/^-?prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $ntparams{prompt} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # pass through | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $ntparams{$_} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $self = $class->SUPER::new(%ntparams) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | *$self->{net_telnet_cisco} = \%params; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | ## Parse all other named args. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | foreach (keys %params) { | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if (/^-?always_waitfor_prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $self->always_waitfor_prompt($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif (/^-?autopage$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->autopage($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | elsif (/^-?ignore_warnings$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $self->ignore_warnings($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | elsif (/^-?more_prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->more_prompt($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif (/^-?normalize_cmd$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->normalize_cmd($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif (/^-?send_wakeup$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->send_wakeup($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | elsif (/^-?waitfor_pause$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->waitfor_pause($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } # end sub new | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # The new prompt() stores the last matched prompt for later | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # fun 'n amusement. You can access this string via $self->last_prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # It also parses out any router errors and stores them in the | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # correct place, where they can be acccessed/handled by the | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # Net::Telnet error methods. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # No POD docs for prompt(); these changes should be transparent to | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # the end-user. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prompt: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my( $self, $prompt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my( $prev, $stream ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $prev = $self->SUPER::prompt; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | ## Parse args. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ( @_ == 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | defined $prompt or $prompt = ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $self->_match_check($prompt); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->SUPER::prompt($prompt); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } elsif (@_ > 2) { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return $self->error('usage: $obj->prompt($match_op)'); | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return $prev; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } # end sub prompt | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # cmd() now parses errors and sticks 'em where they belong. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # This is a routerish error: | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # routereast#show asdf | ||||||||||||||||||||||||||||||||||||||||||
| 166 | # ^ | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # % Invalid input detected at '^' marker. | ||||||||||||||||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||||||||||||||||
| 169 | # "show async" is valid, so the "d" of "asdf" raised an error. | ||||||||||||||||||||||||||||||||||||||||||
| 170 | # | ||||||||||||||||||||||||||||||||||||||||||
| 171 | # If an error message is found, the following error message | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # is sent to Net::Telnet's error()-handler: | ||||||||||||||||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # Last command and router error: | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # <last command prompt> <last command> | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # <error message fills remaining lines> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $normalize = $self->normalize_cmd; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $out = []; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $output_ref; | |||||||||||||||||||||||||||||||||||||||||
| 184 | my %ntparams; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Parse args | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # pull out N::T::C specific (including -output) and pass | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # rest to N::T in %params | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $ {*$self}{net_telnet_cisco}{last_cmd} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $ntparams{string} = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } elsif ( @_ >= 2 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | for (keys(%args)) { | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (/^-?string$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $ {*$self}{net_telnet_cisco}{last_cmd} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $ntparams{string} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | elsif (/^-?normalize_cmd$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $normalize = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | elsif (/^-?output$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $output_ref = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if (defined($output_ref) and ref($output_ref) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $output_ref and ref $output_ref eq "ARRAY"
MC/DC0%0/2
defined $output_ref and ref $output_ref eq "ARRAY"
defined $output_ref
ref $output_ref eq "ARRAY"
Truth table0%0/3
A and B
A= defined $output_refB= ref $output_ref eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $out = $output_ref; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $ntparams{$_} = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $cmd = $ {*$self}{net_telnet_cisco}{last_cmd}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $old_ors = $self->output_record_separator; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $need_more = 0; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | while(1) { | |||||||||||||||||||||||||||||||||||||||||
| 219 | # Send a space (with no newline) whenever we see a "More" prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($need_more) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->output_record_separator(''); | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # We saw a more prompt, so put it in the command output. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my @tmp = $self->last_prompt; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Send the <space>, taking care not to | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # discard the top line. | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | push @tmp, $self->SUPER::cmd(String => " ", Cmd_remove_mode => 0); | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ($normalize) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | push @$out, _normalize(@tmp); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | push @$out, @tmp; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $self->output_record_separator($old_ors); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | push @$out, $self->SUPER::cmd(%ntparams); | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # Look for errors in output | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | for ( my ($i, $lastline) = (0, ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | $i <= $#$out; | ||||||||||||||||||||||||||||||||||||||||||
| 243 | $lastline = $out->[$i++] ) { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # This may have to be a pattern match instead. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ( ( substr $out->[$i], 0, 1 ) eq '%' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ( $out->[$i] =~ /'\^' marker/ ) { # Typo & bad arg errors | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | chomp $lastline; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $self->error( join "\n", | |||||||||||||||||||||||||||||||||||||||||
| 250 | "Last command and router error: ", | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ( $self->last_prompt . $cmd ), | ||||||||||||||||||||||||||||||||||||||||||
| 252 | $lastline, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | $out->[$i], | ||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | splice @$out, $i - 1, 3; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } else { # All other errors. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | chomp $out->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->error( join "\n", | |||||||||||||||||||||||||||||||||||||||||
| 259 | "Last command and router error: ", | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ( $self->last_prompt . $cmd ), | ||||||||||||||||||||||||||||||||||||||||||
| 261 | $out->[$i], | ||||||||||||||||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | splice @$out, $i, 2; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # Restore old settings | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $self->output_record_separator($old_ors); | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | # redo the while loop if we saw a More prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $more_re = $self->_re_sans_delims($self->more_prompt); | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($self->autopage && $self->last_prompt =~ /$more_re/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->autopage and $self->last_prompt =~ /$more_re/
MC/DC0%0/2
$self->autopage and $self->last_prompt =~ /$more_re/
$self->autopage
$self->last_prompt =~ /$more_re/
Truth table0%0/3
A and B
A= $self->autopageB= $self->last_prompt =~ /$more_re/
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $need_more = 1; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if (defined $output_ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if (ref($output_ref) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $$output_ref = join "", @$out; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } elsif (ref($output_ref) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | %$output_ref = @$out; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | return wantarray ? @$out : $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # waitfor now stores prompts to $obj->last_prompt() | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub waitfor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
waitfor: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | # $all_prompts will be built into a regex that matches all currently | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # valid prompts. | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # -Match args will be added to this regex. The current prompt will | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # be appended when all -Matches have been exhausted. | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $all_prompts = ''; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # Literal string matches, passed in with -String. | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my @literals = (); | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Parse the -Match => '/prompt \$' type options | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # waitfor can accept more than one -Match argument, so we can't just | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # hashify the args. | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if (@_ >= 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | while ( my ($k, $v) = splice @args, 0, 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ($k =~ /^-?[Ss]tring$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | push @literals, $v; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } elsif ($k =~ /^-?[Mm]atch$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $all_prompts = $self->_prompt_append($all_prompts, $v); | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | } elsif (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # A single argument is always a -match. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $all_prompts = $self->_prompt_append($all_prompts, $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $all_re = $self->_re_sans_delims($all_prompts); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $prompt_re = $self->_re_sans_delims($self->prompt); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $more_re = $self->_re_sans_delims($self->more_prompt); | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Add the current prompt if it's not already there. You can turn this behavior | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # off by setting always_waitfor_prompt to a false value. | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ($self->always_waitfor_prompt && index($all_re, $prompt_re) == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->always_waitfor_prompt and index($all_re, $prompt_re) == -1
MC/DC0%0/2
$self->always_waitfor_prompt and index($all_re, $prompt_re) == -1
$self->always_waitfor_prompt
index($all_re, $prompt_re) == -1
Truth table0%0/3
A and B
A= $self->always_waitfor_promptB= index($all_re, $prompt_re) == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | unshift @_, "-Match" if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | push @_, (-Match => $self->prompt); | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $all_prompts = $self->_prompt_append($all_prompts, $self->prompt); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $all_re = $self->_re_sans_delims($all_prompts); | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | # Add the more prompt if it's not present. See the autopage() docs | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # to turn this behaviour off. | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ($self->autopage && index($all_re, $more_re) == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->autopage and index($all_re, $more_re) == -1
MC/DC0%0/2
$self->autopage and index($all_re, $more_re) == -1
$self->autopage
index($all_re, $more_re) == -1
Truth table0%0/3
A and B
A= $self->autopageB= index($all_re, $more_re) == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | unshift @_, "-Match" if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | push @_, (-Match => $self->more_prompt); | |||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $all_prompts = $self->_prompt_append($all_prompts, $self->more_prompt); | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $all_re = $self->_re_sans_delims($all_prompts); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | return $self->error("Godot ain't home - waitfor() isn't waiting for anything.") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$all_prompts or @literals
MC/DC0%0/2
$all_prompts or @literals
$all_prompts
@literals
Truth table0%0/3
A or B
A= $all_promptsB= @literals
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | unless $all_prompts || @literals; | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | # There's a timing issue that I can't quite figure out. | ||||||||||||||||||||||||||||||||||||||||||
| 356 | # Adding a small pause here seems to make it go away. | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | select undef, undef, undef, $self->waitfor_pause; | |||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ($prematch, $match) = $self->SUPER::waitfor(@_); | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | # If waitfor saw a prompt then store it. | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ($match) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | for (@literals) { | |||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | if (index $match, $_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | return wantarray ? ($prematch, $match) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ($match =~ /($all_re)/m ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $ {*$self}{net_telnet_cisco}{last_prompt} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | return wantarray ? ($prematch, $match) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | return wantarray ? ( $prematch, $match ) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 380 | my( | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $cmd_prompt, | |||||||||||||||||||||||||||||||||||||||||
| 382 | $endtime, | ||||||||||||||||||||||||||||||||||||||||||
| 383 | $error, | ||||||||||||||||||||||||||||||||||||||||||
| 384 | $lastline, | ||||||||||||||||||||||||||||||||||||||||||
| 385 | $match, | ||||||||||||||||||||||||||||||||||||||||||
| 386 | $orig_errmode, | ||||||||||||||||||||||||||||||||||||||||||
| 387 | $orig_timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 388 | $prematch, | ||||||||||||||||||||||||||||||||||||||||||
| 389 | $reset, | ||||||||||||||||||||||||||||||||||||||||||
| 390 | $timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 391 | $usage, | ||||||||||||||||||||||||||||||||||||||||||
| 392 | $sent_wakeup, | ||||||||||||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | my ($username, $password, $tacpass, $passcode ) = ('','','',''); | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my (%args, %seen); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | ## Init vars. | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $timeout = $self->timeout; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $self->timed_out(''); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | return if $self->eof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $cmd_prompt = $self->prompt; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $sent_wakeup = 0; | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | print "login:\t[orig: $cmd_prompt]\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $usage = 'usage: $obj->login([Name => $name,] [Password => $password,] ' | |||||||||||||||||||||||||||||||||||||||||
| 409 | . '[Passcode => $passcode,] [Prompt => $matchop,] [Timeout => $secs,])'; | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | if (@_ == 3) { # just username and passwd given | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ($username, $password) = (@_[1,2]); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | else { # named args given | ||||||||||||||||||||||||||||||||||||||||||
| 415 | ## Get the named args. | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | (undef, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | ## Parse the named args. | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | foreach (keys %args) { | |||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if (/^-?name$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $username = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 422 | } elsif (/^-?passw/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $password = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } elsif (/^-?passcode/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $passcode = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } elsif (/^-?prompt$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | # login() always looks for a cmd_prompt. This is not | ||||||||||||||||||||||||||||||||||||||||||
| 428 | # controllable via always_waitfor_prompt(). | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $cmd_prompt = $self->_prompt_append($cmd_prompt, $args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 430 | } elsif (/^-?timeout$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $timeout = _parse_timeout($args{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | return $self->error($usage); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | print "login:\t[after args: $cmd_prompt]\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | ## Override these user set-able values. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $endtime = _endtime($timeout); | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $orig_timeout = $self->timeout($endtime); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $orig_errmode = $self->errmode; | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | ## Create a subroutine to reset to original values. | ||||||||||||||||||||||||||||||||||||||||||
| 446 | $reset | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $self->errmode($orig_errmode); | |||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $self->timeout($orig_timeout); | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | ## Create a subroutine to generate an error for user. | ||||||||||||||||||||||||||||||||||||||||||
| 454 | $error | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my($errmsg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | &$reset; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ($self->timed_out) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | return $self->error($errmsg); | |||||||||||||||||||||||||||||||||||||||||
| 461 | } elsif ($self->eof) { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ($lastline = $self->lastline) =~ s/\n+//; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return $self->error($errmsg, ": ", $lastline); | |||||||||||||||||||||||||||||||||||||||||
| 464 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return $self->error($self->errmsg); | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | # Send a newline as the wakeup-call | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | if ($self->send_wakeup eq 'connect') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $sent_wakeup = 1; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $old_sep = $self->output_record_separator; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $self->output_record_separator("\n"); | |||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $self->print(''); | |||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $self->output_record_separator($old_sep); | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | (undef, $_) = $self->waitfor( | |||||||||||||||||||||||||||||||||||||||||
| 485 | -match => '/(?:[Ll]ogin|[Uu]sername|[Pp]assw(?:or)?d)[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 486 | -match => '/(?i:Passcode)[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 487 | -match => $cmd_prompt, | ||||||||||||||||||||||||||||||||||||||||||
| 488 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | unless ($_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | return &$error("read eof waiting for login or password prompt") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | if $self->eof; | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | # We timed-out. Send a newline as the wakeup-call. | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($sent_wakeup == 0 && $self->send_wakeup eq 'timeout') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sent_wakeup == 0 and $self->send_wakeup eq "timeout"
MC/DC0%0/2
$sent_wakeup == 0 and $self->send_wakeup eq "timeout"
$sent_wakeup == 0
$self->send_wakeup eq "timeout"
Truth table0%0/3
A and B
A= $sent_wakeup == 0B= $self->send_wakeup eq "timeout"
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $sent_wakeup = 1; | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $old_sep = $self->output_record_separator; | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->output_record_separator("\n"); | |||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | $self->print(''); | |||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $self->output_record_separator($old_sep); | |||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | return &$error("timed-out during login process"); | |||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $cmd_prompt_re = $self->_re_sans_delims($cmd_prompt); | |||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | if (not defined) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return $self->error("login failed: access denied or bad name, passwd, etc"); | |||||||||||||||||||||||||||||||||||||||||
| 515 | } elsif (/sername|ogin/) { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | $self->print($username) or return &$error("login disconnected"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | $seen{login}++ && $self->error("login failed: access denied or bad username"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | } elsif (/[Pp]assw/) { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | $self->print($password) or return &$error("login disconnected"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $seen{passwd}++ && $self->error("login failed: access denied or bad password"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | } elsif (/(?i:Passcode)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | $self->print($passcode) or return &$error("login disconnected"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | $seen{passcode}++ && $self->error("login failed: access denied or bad passcode"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | } elsif (/($cmd_prompt_re)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | &$reset; # Success. Reset obj to default vals before continuing. | |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 527 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $self->error("login received unexpected prompt. Aborting."); | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 533 | } # end sub login | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | # Overridden to support ignore_warnings() | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | # Ignore warnings | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if ($self->ignore_warnings) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $errmsg = join '', @_; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $warnings_re = $self->_re_sans_delims($self->warnings); | |||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | return if $errmsg =~ /$warnings_re/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | return $self->SUPER::error(@_); | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | # Tries to enter enabled mode with the password arg. | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | sub enable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my $usage = 'usage: $obj->enable([Name => $name,] [Password => $password,] ' | |||||||||||||||||||||||||||||||||||||||||
| 555 | . '[Passcode => $passcode,] [Level => $level] )'; | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | my ($en_username, $en_password, $en_passcode, $en_level) = ('','','',''); | |||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | my ($error, $lastline, $orig_errmode, $reset, %args, %seen); | |||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | if (@_ == 1) { # just passwd given | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ($en_password) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 561 | } else { # named args given | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | foreach (keys %args) { | |||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if (/^-?name$|^-?login$|^-?user/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $en_username = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } elsif (/^-?passw/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | $en_password = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 569 | } elsif (/^-?passc/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $en_passcode = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 571 | } elsif (/^-?level$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $en_level = $args{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 573 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | return $self->error($usage); | |||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | ## Create a subroutine to generate an error for user. | ||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | $error = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my($errmsg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if ($self->timed_out) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | return $self->error($errmsg); | |||||||||||||||||||||||||||||||||||||||||
| 585 | } elsif ($self->eof) { | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ($lastline = $self->lastline) =~ s/\n+//; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | return $self->error($errmsg, ": ", $lastline); | |||||||||||||||||||||||||||||||||||||||||
| 588 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | return $self->error($errmsg); | |||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | # Store the old prompt without the //s around it. | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my ($old_prompt) = $self->_re_sans_delims($self->prompt); | |||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | # We need to expect either a Password prompt or a | ||||||||||||||||||||||||||||||||||||||||||
| 597 | # typical prompt. If the user doesn't have enough | ||||||||||||||||||||||||||||||||||||||||||
| 598 | # access to run the 'enable' command, the device | ||||||||||||||||||||||||||||||||||||||||||
| 599 | # won't even query for a password, it will just | ||||||||||||||||||||||||||||||||||||||||||
| 600 | # ignore the command and display another [boring] prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | $self->print("enable $en_level"); | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | { | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my ($prematch, $match) = $self->waitfor( | |||||||||||||||||||||||||||||||||||||||||
| 605 | -match => '/[Ll]ogin[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 606 | -match => '/[Uu]sername[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 607 | -match => '/[Pp]assw(?:or)?d[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 608 | -match => '/(?i:Passcode)[:\s]*$/', | ||||||||||||||||||||||||||||||||||||||||||
| 609 | -match => "/$old_prompt/", | ||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | ) or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | return &$error("read eof waiting for enable login or password prompt") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | if $self->eof; | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | return &$error("timed-out waiting for enable login or password prompt"); | |||||||||||||||||||||||||||||||||||||||||
| 614 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | if (not defined $match) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | return &$error("enable failed: access denied or bad name, passwd, etc"); | |||||||||||||||||||||||||||||||||||||||||
| 618 | } elsif ($match =~ /sername|ogin/) { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | $self->print($en_username) or return &$error("enable failed"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | $seen{login}++ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | && return &$error("enable failed: access denied or bad username"); | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||
| 623 | } elsif ($match =~ /[Pp]assw/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | $self->print($en_password) or return &$error("enable failed"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | $seen{passwd}++ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | && return &$error("enable failed: access denied or bad password"); | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||
| 628 | } elsif ($match =~ /(?i:Passcode)/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | $self->print($en_passcode) or return &$error("enable failed"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | $seen{passcode}++ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | && return &$error("enable failed: access denied or bad passcode"); | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | redo; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } elsif ($match =~ /$old_prompt/) { | ||||||||||||||||||||||||||||||||||||||||||
| 634 | ## Success! Exit the block. | ||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 636 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | return &$error("enable received unexpected prompt. Aborting."); | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if (($en_level eq '') or ($en_level =~ /^[1-9]/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$en_level eq "" or $en_level =~ /^[1-9]/
MC/DC0%0/2
$en_level eq "" or $en_level =~ /^[1-9]/
$en_level eq ""
$en_level =~ /^[1-9]/
Truth table0%0/3
A or B
A= $en_level eq ""B= $en_level =~ /^[1-9]/
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | # Prompts and levels over 1 give a #/(enable) prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | return $self->is_enabled ? 1 : &$error('Failed to enter enable mode'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 645 | # Assume success | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | # Leave enabled mode. | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | sub disable { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | $self->cmd('disable'); | |||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | return $self->is_enabled ? $self->error('Failed to exit enabled mode') : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | sub fhopen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fhopen: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | $self->SUPER::fhopen(@_); | |||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | *$self->{net_telnet_cisco} = $stream; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | # Send control-^ (without newline) | ||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub ios_break { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ios_break: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my $old_ors = $self->output_record_separator; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | $self->output_record_separator(''); | |||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my $ret = $self->print("\c^"); | |||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | $self->output_record_separator($old_ors); | |||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | # Displays the last prompt. | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | sub last_prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_prompt: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | exists $stream->{last_prompt} ? $stream->{last_prompt} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | # Displays the last command. | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | sub last_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_cmd: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | exists $stream->{last_cmd} ? $stream->{last_cmd} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | # Examines the last prompt to determine the current mode. | ||||||||||||||||||||||||||||||||||||||||||
| 693 | # Some prompts may be hard set to #, so this won't always return a valid answer. | ||||||||||||||||||||||||||||||||||||||||||
| 694 | # Call 'show priv' instead. | ||||||||||||||||||||||||||||||||||||||||||
| 695 | # 1 => enabled. | ||||||||||||||||||||||||||||||||||||||||||
| 696 | # undef => not enabled. | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | sub is_enabled { $_[0]->last_prompt =~ /\#|enable|config/ ? 1 : undef } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_enabled: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | sub always_waitfor_prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
always_waitfor_prompt: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | $stream->{always_waitfor_prompt} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | return $stream->{always_waitfor_prompt}; | |||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | sub waitfor_pause { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
waitfor_pause: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | $stream->{waitfor_pause} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | return $stream->{waitfor_pause}; | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | sub autopage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autopage: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | $stream->{autopage} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | return $stream->{autopage}; | |||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | sub normalize_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_cmd: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | $stream->{normalize_cmd} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | return $stream->{normalize_cmd}; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | sub send_wakeup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_wakeup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | $stream->{send_wakeup} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | return $stream->{send_wakeup}; | |||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | # Typical get/set method. | ||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | sub ignore_warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ignore_warnings: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | $stream->{ignore_warnings} = $arg if defined $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 0 | return $stream->{ignore_warnings}; | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | # Get/set the More prompt | ||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | sub more_prompt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
more_prompt: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | if (defined $arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | $self->_match_check($arg); | |||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | $stream->{more_prompt} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | return $stream->{more_prompt}; | |||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | sub warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warnings: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my ($self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | my $stream = $ {*$self}{net_telnet_cisco}; | |||||||||||||||||||||||||||||||||||||||||
| 761 | 0 | ▶ | if (defined $arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $self->_match_check($arg); | |||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | $stream->{warnings} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | return $stream->{warnings}; | |||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 769 | # Private methods | ||||||||||||||||||||||||||||||||||||||||||
| 770 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | # Join two or more regexen into one on "|". | ||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | ▶ | sub _prompt_append { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prompt_append: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | my $orig = shift || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | return $self->error("usage: \$obj->_prompt_append(orig, new, [new...])") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | unless @_; | ||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | print "_prompt_append:\t[original: $orig]\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | if ($orig) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | if ($self->_match_check($orig)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $orig = $self->_re_sans_delims($orig); | |||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | return $self->error("Can't parse prompt: '$orig'") unless $orig; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | print "_prompt_append:\t[append: $_]\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | if ($self->_match_check($_)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | my $re = $self->_re_sans_delims($_); | |||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | unless ($re) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $self->error("Can't parse prompt: '$_'"); | |||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | $orig .= $orig ? "|$re" : $re; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | print "_prompt_append:\t[return: /$orig/]\n\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | return "/$orig/"; | |||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | # Return a Net::Telnet regular expression without the delimiters. | ||||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | sub _re_sans_delims { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_re_sans_delims: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 0 | my ($self, $str) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | return $self->error("usage: \$obj->_re_sans_delims(\$matchop)") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | unless $str; | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | $self->_match_check($str); | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | my ($delim, $re) = $str =~ /^\s*m?\s*(\W)(.*)\1\s*$/; | |||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | return $re; | |||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||
| 818 | # strip backspaces, deletes, kills, and the character they | ||||||||||||||||||||||||||||||||||||||||||
| 819 | # pertain to, from an array. | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | sub _normalize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | $_ = join "", @_; | |||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | 1 while s/[^\cH\c?][\cH\c?]//mg; # ^H ^? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | s/^.*\cU//mg; # ^U | |||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | ▶ | return wantarray ? split /^/, $_ : $_; # ORS instead? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | # Lifted from Net::Telnet en toto | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | sub _match_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_match_check: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | return unless $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | 0 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 835 | 0 | my @warns = (); | |||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | 0 | ▶ | print "_match_check:\t[Checking: $code]\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | ## Use eval to check for syntax errors or warnings. | ||||||||||||||||||||||||||||||||||||||||||
| 840 | { | ||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | local $SIG{'__DIE__'} = 'DEFAULT'; | |||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | ▶ | local $SIG{'__WARN__'} = sub { push @warns, @_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | local $^W = 1; | |||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | local $_ = ''; | |||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | eval "\$_ =~ $code;"; | |||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 848 | ## Remove useless lines numbers from message. | ||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | ($error = $@) =~ s/ at \(eval \d+\) line \d+.?//; | |||||||||||||||||||||||||||||||||||||||||
| 850 | 0 | chomp $error; | |||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | return $self->error("bad match operator: $error"); | |||||||||||||||||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||||||||||||||||
| 853 | elsif (@warns) { | ||||||||||||||||||||||||||||||||||||||||||
| 854 | ## Remove useless lines numbers from message. | ||||||||||||||||||||||||||||||||||||||||||
| 855 | 0 | ($error = shift @warns) =~ s/ at \(eval \d+\) line \d+.?//; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | $error =~ s/ while "strict subs" in use//; | |||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | chomp $error; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | return $self->error("bad match operator: $error"); | |||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||
| 861 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 862 | } # end sub _match_check | ||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||
| 864 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 865 | # Class methods | ||||||||||||||||||||||||||||||||||||||||||
| 866 | #------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||
| 868 | # Look for subroutines in Net::Telnet if we can't find them here. | ||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | ▶ | croak "$self is an [unexpected] object, aborting" if ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | $AUTOLOAD =~ s/.*::/Net::Telnet::/; | |||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | __END__ | ||||||||||||||||||||||||||||||||||||||||||