| 1 | package CPAN::Mini::Inject::REST::Client::Command::dist; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use base 'CPAN::Mini::Inject::REST::Client::Command'; | ||
| 7 | |||
| 8 | |||
| 9 | #--Command usage---------------------------------------------------------------- | ||
| 10 | |||
| 11 | sub usage_desc { | ||
| 12 | return "dist %o <distribution_name>"; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub abstract { | ||
| 16 | return "Lists distribution files contained in the mirror and repository"; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub description { | ||
| 20 | return "Lists distribution files contained in the mirror and repository"; | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | #--Command specific options----------------------------------------------------- | ||
| 25 | |||
| 26 | sub options { | ||
| 27 | my ($class, $app) = @_; | ||
| 28 | |||
| 29 | return undef; | ||
| 30 | } | ||
| 31 | |||
| 32 | |||
| 33 | #--Validate args---------------------------------------------------------------- | ||
| 34 | |||
| 35 | sub validate_args { | ||
| 36 | my ($self, $opt, $args) = @_; | ||
| 37 | |||
| 38 | $self->usage_error('Distribution name must be specified') unless @$args; | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 42 | #--Command execute method------------------------------------------------------- | ||
| 43 | |||
| 44 | sub execute { | ||
| 45 | my ($self, $opt, $args) = @_; | ||
| 46 | |||
| 47 | my $dist = shift @$args; | ||
| 48 | my ($code, $result) = $self->api($opt)->get("dist/$dist"); | ||
| 49 | |||
| 50 | given ($code) { | ||
| 51 | when (200) { | ||
| 52 | say "Mirror:"; | ||
| 53 | say " $_" foreach @{$result->{mirror}}; | ||
| 54 | say ""; | ||
| 55 | say "Repository:"; | ||
| 56 | say " $_" foreach @{$result->{repository}}; | ||
| 57 | } | ||
| 58 | when (404) { | ||
| 59 | die "Distribution $dist cannot be found\n" | ||
| 60 | } | ||
| 61 | default { | ||
| 62 | die "Cannot retrieve distribution info - unknown error!\n"; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | #------------------------------------------------------------------------------- | ||
| 69 | |||
| 70 | 1; |