package SSHSentry; use strict; use warnings; sub new { my ($class, %params) = @_; my $self = bless {}, $class; foreach my $func (keys %params) { next unless $self->can($func); $self->$func($params{$func}); } return $self; } sub ssh_handle { my ($self, $handle) = @_; if (defined $handle and ref $handle eq 'Net::SSH') { # Assuming Net::SSH is used for ssh handle. If not, change this. $self->{ssh_handle} = $handle; } return $self->{ssh_handle}; } sub DESTROY { my $self = shift; my $ssh = $self->ssh_handle() or return; $ssh->exit_session(); $ssh->close_session(); } 1;