File Coverage

blib/lib/WWW/ARDB/CLI/Cmd/Item.pm
Criterion Covered Total %
statement 9 57 15.7
branch 0 16 0.0
condition 0 11 0.0
subroutine 3 5 60.0
pod 0 1 0.0
total 12 90 13.3


line stmt bran cond sub pod time code
1             package WWW::ARDB::CLI::Cmd::Item;
2             our $AUTHORITY = 'cpan:GETTY';
3              
4             # ABSTRACT: Show item details command
5              
6 2     2   3392 use Moo;
  2         4  
  2         18  
7 2     2   1023 use MooX::Cmd;
  2         5  
  2         17  
8 2     2   6390 use JSON::MaybeXS;
  2         5  
  2         1641  
9              
10             our $VERSION = '0.002';
11              
12              
13             sub execute {
14 0     0 0   my ($self, $args, $chain) = @_;
15 0           my $app = $chain->[0];
16              
17 0           my $id = $args->[0];
18 0 0         unless ($id) {
19 0           print "Usage: ardb item \n";
20 0           print "Example: ardb item acoustic_guitar\n";
21 0           return;
22             }
23              
24 0           my $item = $app->api->item($id);
25              
26 0 0         unless ($item) {
27 0           print "Item not found: $id\n";
28 0           return;
29             }
30              
31 0 0         if ($app->json) {
32 0           print JSON::MaybeXS->new(utf8 => 1, pretty => 1)->encode($item->_raw);
33 0           return;
34             }
35              
36 0           print "=" x 60 . "\n";
37 0           print $item->name . "\n";
38 0           print "=" x 60 . "\n\n";
39              
40 0           _print_field("ID", $item->id);
41 0           _print_field("Type", $item->type);
42 0           _print_field("Rarity", $item->rarity);
43 0           _print_field("Value", $item->value);
44 0           _print_field("Weight", $item->weight);
45 0           _print_field("Stack Size", $item->stack_size);
46              
47 0 0         if ($item->description) {
48 0           print "\nDescription:\n";
49 0           print " " . $item->description . "\n";
50             }
51              
52 0 0         if (@{$item->found_in}) {
  0            
53 0           print "\nFound In:\n";
54 0           for my $loc (@{$item->found_in}) {
  0            
55 0           print " - $loc\n";
56             }
57             }
58              
59 0 0         if (@{$item->breakdown}) {
  0            
60 0           print "\nBreakdown Components:\n";
61 0           for my $comp (@{$item->breakdown}) {
  0            
62             printf " - %dx %s (%s)\n",
63             $comp->{amount} // 1,
64             $comp->{name},
65 0   0       $comp->{rarity} // 'common';
      0        
66             }
67             }
68              
69 0 0         if (@{$item->crafting}) {
  0            
70 0           print "\nCrafting Requirements:\n";
71 0           for my $req (@{$item->crafting}) {
  0            
72             printf " - %dx %s\n",
73             $req->{amount} // 1,
74 0   0       $req->{name} // $req->{id};
      0        
75             }
76             }
77              
78 0   0       print "\nLast Updated: " . ($item->updated_at // 'unknown') . "\n";
79             }
80              
81             sub _print_field {
82 0     0     my ($label, $value) = @_;
83 0 0         return unless defined $value;
84 0           printf "%-15s %s\n", "$label:", $value;
85             }
86              
87             1;
88              
89             __END__