in reply to Re^2: exiting a subroutine neatly
in thread exiting a subroutine neatly
use Try::Catch qw/ try catch finally /; sub foo { ... try { fooFoo($ssh); } catch { warn "warn cought one: $_"; }; $ssh->exit_session; $ssh->close_session; } sub fooFoo { my ($ssh) = @_; if ( !$ssh->start_session($ssh_host) ) { MyErr->throw("ERROR connecting to $ssh_host"); } my ( $ret, $err ) = $ssh->execute( 'command1', 'expect1' ); if ( $err || $ret =~ /Unknown command:/m ) { MyErr->throw({err => $err, ret => $ret, execute => [ 'command1 +', 'expect1' ] ); } my ( $ret, $err ) = $ssh->execute( 'command2', 'expect2' ); if ( $err || $ret =~ /Unknown command:/m ) { MyErr->throw({err => $err, ret => $ret, execute => [ 'command2 +', 'expect2' ] ); } return; } { package MyErr; use Moo; with 'Throwable'; has err => (is => 'ro'); has ret => (is => 'ro'); has execute => (is => 'ro'); 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: exiting a subroutine neatly (Throwable)
by salva (Canon) on May 05, 2015 at 10:51 UTC | |
by Anonymous Monk on May 05, 2015 at 11:08 UTC | |
by salva (Canon) on May 05, 2015 at 11:28 UTC | |
by Anonymous Monk on May 05, 2015 at 16:43 UTC |