File Coverage

blib/lib/WWW/MetaForge/ArcRaiders/CLI/Cmd/Item.pm
Criterion Covered Total %
statement 56 86 65.1
branch 15 32 46.8
condition 11 50 22.0
subroutine 7 7 100.0
pod 1 1 100.0
total 90 176 51.1


line stmt bran cond sub pod time code
1             package WWW::MetaForge::ArcRaiders::CLI::Cmd::Item;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Show details for a single item
4             our $VERSION = '0.002';
5 1     1   11592 use Moo;
  1         3  
  1         14  
6 1     1   640 use MooX::Cmd;
  1         3  
  1         13  
7 1     1   8008 use MooX::Options;
  1         2  
  1         12  
8 1     1   6114 use JSON::MaybeXS;
  1         3  
  1         1619  
9              
10             sub execute {
11 3     3 1 6574 my ($self, $args, $chain) = @_;
12 3         10 my $app = $chain->[0];
13              
14 3         9 my $slug = $args->[0];
15 3 100       14 unless ($slug) {
16 1         61 print "Usage: arcraiders item <slug>\n";
17 1         37 print "Example: arcraiders item wasp-driver\n";
18 1         10 return;
19             }
20              
21             # Search for item - try multiple search strategies
22 2         83 my $items = $app->api->items(search => $slug);
23              
24             # If no results, try converting slug to search term (ferro-i -> ferro)
25 2 50 33     847 if (!@$items && $slug =~ /-/) {
26 0         0 my $search_term = $slug;
27 0         0 $search_term =~ s/-[ivx]+$//i; # Remove roman numeral suffix
28 0         0 $search_term =~ s/-/ /g; # Replace dashes with spaces
29 0 0       0 $items = $app->api->items(search => $search_term) if $search_term ne $slug;
30             }
31              
32             # Find exact match by slug or id first
33             my ($item) = grep {
34 2 100 33     9 ($_->slug && lc($_->slug) eq lc($slug)) ||
  16   66     127  
35             ($_->id && lc($_->id) eq lc($slug))
36             } @$items;
37              
38 2 50       30 unless ($item) {
39 0 0       0 if (@$items == 1) {
    0          
40 0         0 $item = $items->[0];
41             } elsif (@$items > 1) {
42 0         0 print "Multiple items match '$slug':\n";
43 0         0 for my $m (@$items) {
44 0   0     0 printf " %s [%s]\n", $m->name // 'Unknown', $m->slug // $m->id // '-';
      0        
      0        
45             }
46 0         0 return;
47             } else {
48 0         0 print "Item '$slug' not found.\n";
49 0         0 return;
50             }
51             }
52              
53 2 100       15 if ($app->json) {
54 1         8 print JSON::MaybeXS->new(utf8 => 1, pretty => 1)->encode($item->_raw);
55 1         178 return;
56             }
57              
58 1         5 _print_item_details($item);
59             }
60              
61             sub _print_item_details {
62 1     1   3 my ($item) = @_;
63              
64 1         69 print "=" x 60, "\n";
65 1   50     50 printf "%s\n", $item->name // 'Unknown';
66 1         24 print "=" x 60, "\n";
67              
68 1   33     78 _print_field("ID", $item->slug // $item->id);
69 1         11 _print_field("Category", $item->category);
70 1         8 _print_field("Rarity", $item->rarity);
71 1         11 _print_field("Weight", $item->weight);
72 1         14 _print_field("Stack Size", $item->stack_size);
73 1         9 _print_field("Base Value", $item->base_value);
74              
75 1 50       9 if ($item->description) {
76 1         21 print "\nDescription:\n";
77 1         22 print " ", $item->description, "\n";
78             }
79              
80 1 50 33     28 if ($item->stats && %{$item->stats}) {
  1         8  
81 1         25 print "\nStats:\n";
82 1         4 for my $key (sort keys %{$item->stats}) {
  1         12  
83 6   50     220 printf " %-30s %s\n", $key, $item->stats->{$key} // '-';
84             }
85             }
86              
87 1 50 33     12 if ($item->crafting_requirements && @{$item->crafting_requirements}) {
  1         25  
88 0         0 print "\nCrafting Requirements:\n";
89 0         0 for my $req (@{$item->crafting_requirements}) {
  0         0  
90 0   0     0 my $name = $req->{item} // $req->{name} // 'Unknown';
      0        
91 0   0     0 my $qty = $req->{quantity} // $req->{amount} // 1;
      0        
92 0         0 printf " %dx %s\n", $qty, $name;
93             }
94             }
95              
96 1 50 33     7 if ($item->sold_by && @{$item->sold_by}) {
  1         6  
97 0         0 print "\nSold By:\n";
98 0         0 for my $seller (@{$item->sold_by}) {
  0         0  
99 0 0       0 if (ref $seller eq 'HASH') {
100 0   0     0 printf " %s\n", $seller->{name} // $seller->{trader} // 'Unknown';
      0        
101             } else {
102 0         0 printf " %s\n", $seller;
103             }
104             }
105             }
106              
107 1 50 33     17 if ($item->recycle_yield && %{$item->recycle_yield}) {
  0         0  
108 0         0 print "\nRecycle Yield:\n";
109 0         0 for my $mat (sort keys %{$item->recycle_yield}) {
  0         0  
110 0         0 printf " %dx %s\n", $item->recycle_yield->{$mat}, $mat;
111             }
112             }
113              
114 1 50       51 if ($item->last_updated) {
115 0         0 print "\nLast Updated: ", $item->last_updated, "\n";
116             }
117             }
118              
119             sub _print_field {
120 6     6   19 my ($label, $value) = @_;
121 6 50       19 return unless defined $value;
122 6         1884 printf "%-15s %s\n", "$label:", $value;
123             }
124              
125             1;
126              
127             __END__
128              
129             =pod
130              
131             =encoding UTF-8
132              
133             =head1 NAME
134              
135             WWW::MetaForge::ArcRaiders::CLI::Cmd::Item - Show details for a single item
136              
137             =head1 VERSION
138              
139             version 0.002
140              
141             =head1 SYNOPSIS
142              
143             # Show details for an item by slug
144             arcraiders item wasp-driver
145              
146             # Show details for an item with roman numerals
147             arcraiders item ferro-i
148              
149             # Output as JSON
150             arcraiders --json item wasp-driver
151              
152             =head1 DESCRIPTION
153              
154             This CLI command displays detailed information for a single item in Arc Raiders.
155             The command searches for items by slug or ID, supporting fuzzy matching for items
156             with roman numeral suffixes (e.g., C<ferro-i> will search for "ferro").
157              
158             If multiple items match the search term, all matches are listed. If exactly one
159             item matches, or an exact slug/ID match is found, detailed information is displayed
160             including:
161              
162             =over 4
163              
164             =item * Name, category, rarity
165              
166             =item * Weight, stack size, base value
167              
168             =item * Description and stats
169              
170             =item * Crafting requirements
171              
172             =item * Vendors that sell the item
173              
174             =item * Recycle yield
175              
176             =item * Last updated timestamp
177              
178             =back
179              
180             =head2 execute
181              
182             $cmd->execute($args, $chain);
183              
184             Executes the item detail command. Takes a single argument (the item slug or ID)
185             and displays comprehensive information about the item. If C<--json> flag is set
186             in the parent application, outputs raw JSON data instead of formatted text.
187              
188             =head1 SUPPORT
189              
190             =head2 Issues
191              
192             Please report bugs and feature requests on GitHub at
193             L<https://github.com/Getty/p5-www-metaforge/issues>.
194              
195             =head2 IRC
196              
197             You can reach Getty on C<irc.perl.org> for questions and support.
198              
199             =head1 CONTRIBUTING
200              
201             Contributions are welcome! Please fork the repository and submit a pull request.
202              
203             =head1 AUTHOR
204              
205             Torsten Raudssus <torsten@raudssus.de>
206              
207             =head1 COPYRIGHT AND LICENSE
208              
209             This software is copyright (c) 2026 by Torsten Raudssus.
210              
211             This is free software; you can redistribute it and/or modify it under
212             the same terms as the Perl 5 programming language system itself.
213              
214             =cut