Client/Command/file.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 54 CC 2 SCAR 10.0
CC
2
Cov
0%
validate_args
6.0
usage_desc
2.0
abstract
2.0
CRAP 2.7
1 package CPAN::Mini::Inject::REST::Client::Command::file;
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 "file %o <filename>";
13 }
14  
15 sub abstract {
16 return "Provides file details as indexed by the mirror";
17 }
18  
19 sub description {
20 return "Provides file details as indexed by the mirror";
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('Filename must be specified') unless @$args;
39 }
40  
41  
42 #--Command execute method-------------------------------------------------------
43  
44 sub execute {
45 my ($self, $opt, $args) = @_;
46  
47 my $file = shift @$args;
48 my ($code, $result) = $self->api($opt)->get("mirror/$file");
49
50 given ($code) {
51 when (200) {
52 say "Path:";
53 say " " . $result->{path};
54 say "";
55 say "Modules:";
56 foreach my $module (sort keys %{$result->{provides}}) {
57 my $version = $result->{provides}->{$module}->{version};
58 say " $module ($version)";
59 }
60 }
61 when (404) {
62 die "File $file cannot be found\n"
63 }
64 default {
65 die "Cannot retrieve file info - unknown error!\n";
66 }
67 }
68 }
69  
70  
71 #-------------------------------------------------------------------------------
72  
73 1;