File Coverage

blib/lib/CPAN/Mini/Inject/REST/Client/Command.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package CPAN::Mini::Inject::REST::Client::Command;
2              
3 1     1   954 use 5.010;
  1         4  
  1         37  
4 1     1   5 use strict;
  1         2  
  1         26  
5 1     1   5 use warnings;
  1         2  
  1         28  
6 1     1   6 use App::Cmd::Setup -command;
  1         2  
  1         6  
7 1     1   769 use CPAN::Mini::Inject::REST::Client::API;
  0            
  0            
8              
9              
10             #--Define default options for all commands--------------------------------------
11              
12             sub opt_spec {
13             my ( $class, $app ) = @_;
14             return (
15             [ 'protocol=s' => "Network protocol ('http' or 'https')", {default => $app->config->{protocol} || 'http'} ],
16             [ 'host=s' => "Hostname of your CPAN server", {default => $app->config->{host} || '127.0.0.1'} ],
17             [ 'port=i' => "CPAN server port number", {default => $app->config->{port} || '80'} ],
18             [ 'username=s' => "Username (if using HTTP basic auth)", {default => $app->config->{username} || undef} ],
19             [ 'password=s' => "Password (if using HTTP basic auth)", {default => $app->config->{password} || undef} ],
20             $class->options($app),
21             );
22             }
23              
24              
25             #--Build the API object---------------------------------------------------------
26              
27             sub api {
28             my ($self, $opt) = @_;
29            
30             my $api_options = {
31             protocol => $opt->{protocol},
32             host => $opt->{host},
33             port => $opt->{port},
34             };
35            
36             $opt->{username} && do {$api_options->{username} = $opt->{username}};
37             $opt->{password} && do {$api_options->{password} = $opt->{password}};
38            
39             return CPAN::Mini::Inject::REST::Client::API->new($api_options);
40             }
41              
42              
43             #-------------------------------------------------------------------------------
44              
45             1;