Skip to content

Commit

Permalink
add conditional loading example
Browse files Browse the repository at this point in the history
  • Loading branch information
salva committed Mar 15, 2013
1 parent ff9ef85 commit ffa7f10
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension Net::OpenSSH::Compat.

0.07
- add conditional_loading example

0.06 Sep 28, 2011
- in SSH2:
- honor use_pty configuration flag from shell method
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -13,3 +13,4 @@ t/Net-OpenSSH-Compat.t
t/Net-SSH.t
t/Net-SSH-Perl.t
t/pods.t
examples/conditional_loading.pl
41 changes: 41 additions & 0 deletions examples/conditional_loading.pl
@@ -0,0 +1,41 @@
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %connection_details = ( host => 'localhost', @ARGV);
my $ssh = ssh_connection(%connection_details);
print "ssh: ", Dumper($ssh), "\n";
exit (0);

BEGIN {
eval {
require Net::SSH2;
warn "Net::SSH2 loaded";
1;
} or eval {
require Net::OpenSSH::Compat::SSH2;
Net::OpenSSH::Compat::SSH2->import(':supplant');
warn "Net::SSH2 supplanted";
1;
} or die "unable to load any SSH module: $@";
Net::SSH2->import();
}


sub ssh_connection {
my (%connection_info) = @_;

## Connect to the ssh server
my $ssh = Net::SSH2->new();

$ssh->connect($connection_info{'host'},22)
or die "Unable to connect to the remote ssh server \n\n $@";

## Login to ssh server
$ssh->auth_password($connection_info{'user'},$connection_info{'pass'})
or die "Unable to login Check username and password. \n\n $@\n";

return $ssh;
}

0 comments on commit ffa7f10

Please sign in to comment.