File Coverage

blib/lib/Net/SSH/Mechanize/ConnectParams.pm
Criterion Covered Total %
statement 3 9 33.3
branch 0 4 0.0
condition n/a
subroutine 1 2 50.0
pod 1 1 100.0
total 5 16 31.2


line stmt bran cond sub pod time code
1             package Net::SSH::Mechanize::ConnectParams;
2 5     5   40 use Moose;
  5         12  
  5         34  
3              
4             our $VERSION = '0.1.2'; # VERSION
5              
6             has 'host' => (
7             isa => 'Str',
8             is => 'rw',
9             required => 1,
10             );
11              
12             has 'user' => (
13             isa => 'Str',
14             is => 'rw',
15             );
16              
17             has 'password' => (
18             isa => 'Str',
19             is => 'rw',
20             predicate => 'has_password',
21             );
22              
23             has 'port' => (
24             isa => 'Int',
25             is => 'rw',
26             default => 22,
27             );
28              
29             sub ssh_cmd {
30 0     0 1   my $self = shift;
31              
32 0           my @cmd = ('-t', $self->host, 'sh');
33              
34 0 0         unshift @cmd, defined $self->user? ('-l', $self->user) : ();
35 0 0         unshift @cmd, defined $self->port? ('-p', $self->port) : ();
36 0           unshift @cmd, '/usr/bin/ssh';
37 0           return @cmd;
38             }
39              
40              
41              
42             __PACKAGE__->meta->make_immutable;
43             1;
44             __END__
45              
46             =head1 NAME
47              
48             Net::SSH::Mechanize::ConnectParams - encapsulates information about an ssh connection
49              
50             =head1 VERSION
51              
52             version 0.1.2
53              
54             =head1 SYNOPSIS
55              
56             This class is just a container for log-in details with a method which
57             constructs an approprate C<ssh> command invocation.
58              
59             This equates to C</usr/bin/ssh -t somewhere.com sh>:
60              
61             my $minimal_params = Net::SSH::Mechanize::ConnectParams->new(
62             host => 'somewhere.com',
63             );
64              
65             This equates to C</usr/bin/ssh -l someone -p 999 -t somewhere.com sh>:
66              
67             my $all_params = Net::SSH::Mechanize::ConnectParams->new(
68             host => 'somewhere.com',
69             user => 'someone',
70             port => 999,
71             password => 'secret',
72             );
73              
74             =head1 CLASS METHODS
75              
76             =head2 C<< $obj = $class->new(%parameters) >>
77              
78             Creates a new instance. Parameters is a hash or a list of key-value
79             parameters. Valid parameter keys are:
80              
81             =over 4
82              
83             =item C<host>
84              
85             The hostname to connect to (a scalar string). Either this or C<connection_params> must
86             be supplied.
87              
88             =item C<user>
89              
90             The name of the user account to log into (a scalar string). If not
91             given, no user will be supplied to C<ssh> (this typically means it
92             will use the current user as default).
93              
94             =item C<port>
95              
96             The port to connect to (a positive scalar integer; C<ssh> will default
97             to 22 if this is not specificed).
98              
99             =item C<password>
100              
101             The password to connect with (a scalar string). This is only required
102             if authentication will be performed, either on log-in or when sudoing.
103              
104             =back
105              
106             =head1 INSTANCE ATTRIBUTES
107              
108             =head2 C<< $obj->host >>
109             =head2 C<< $obj->user >>
110             =head2 C<< $obj->password >>
111             =head2 C<< $obj->port >>
112              
113             These are all read-write accessors for the attribute parameters
114             accepted by the constructor.
115              
116             =head1 INSTANCE METHODS
117              
118             =head2 C<< $cmd = $obj->ssh_cmd >>
119              
120             This constructs the C<ssh> command to invoke. If you need something
121             different, you can create a subclass which overrides this method, and
122             pass that via the C<connection_params> parameter to
123             C<< Net::SSH::Mechanize->new() >>.
124              
125              
126             =head1 AUTHOR
127              
128             Nick Stokoe C<< <wulee@cpan.org> >>
129              
130              
131             =head1 LICENCE AND COPYRIGHT
132              
133             Copyright (c) 2011, Nick Stokoe C<< <wulee@cpan.org> >>. All rights reserved.
134              
135             This module is free software; you can redistribute it and/or
136             modify it under the same terms as Perl itself. See L<perlartistic>.