File Coverage

blib/lib/WWW/MetaForge/ArcRaiders/Result/Item.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition 18 29 62.0
subroutine 4 4 100.0
pod 1 1 100.0
total 41 52 78.8


line stmt bran cond sub pod time code
1             package WWW::MetaForge::ArcRaiders::Result::Item;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Item result object
4             our $VERSION = '0.002';
5 6     6   343693 use Moo;
  6         10141  
  6         47  
6 6     6   5159 use Types::Standard qw(Str Int Num ArrayRef HashRef Maybe);
  6         161970  
  6         69  
7 6     6   20163 use namespace::clean;
  6         19508  
  6         54  
8              
9             has id => (
10             is => 'ro',
11             isa => Str,
12             required => 1,
13             );
14              
15             has name => (
16             is => 'ro',
17             isa => Str,
18             required => 1,
19             );
20              
21             has slug => (
22             is => 'ro',
23             isa => Maybe[Str],
24             );
25              
26             has category => (
27             is => 'ro',
28             isa => Maybe[Str],
29             );
30              
31             has rarity => (
32             is => 'ro',
33             isa => Maybe[Str],
34             );
35              
36             has description => (
37             is => 'ro',
38             isa => Maybe[Str],
39             );
40              
41             has stats => (
42             is => 'ro',
43             isa => Maybe[HashRef],
44             );
45              
46             has weight => (
47             is => 'ro',
48             isa => Maybe[Num],
49             );
50              
51             has stack_size => (
52             is => 'ro',
53             isa => Maybe[Int],
54             );
55              
56             has base_value => (
57             is => 'ro',
58             isa => Maybe[Int],
59             );
60              
61             has crafting_requirements => (
62             is => 'ro',
63             isa => ArrayRef[HashRef],
64             default => sub { [] },
65             );
66              
67             has sold_by => (
68             is => 'ro',
69             isa => ArrayRef[HashRef],
70             default => sub { [] },
71             );
72              
73             has used_in => (
74             is => 'ro',
75             isa => ArrayRef,
76             default => sub { [] },
77             );
78              
79             has compatible_with => (
80             is => 'ro',
81             isa => ArrayRef,
82             default => sub { [] },
83             );
84              
85             has recycle_yield => (
86             is => 'ro',
87             isa => Maybe[HashRef],
88             );
89              
90             has last_updated => (
91             is => 'ro',
92             isa => Maybe[Str],
93             );
94              
95             has _raw => (
96             is => 'ro',
97             isa => HashRef,
98             );
99              
100             sub from_hashref {
101 132     132 1 37401 my ($class, $data) = @_;
102              
103             # Handle both documented and actual API field names
104 132   66     586 my $stats = $data->{stats} // $data->{stat_block};
105 132 100 66     450 my $weight = $data->{weight} // ($stats ? $stats->{weight} : undef);
106 132 100 66     404 my $stack_size = $data->{stackSize} // ($stats ? $stats->{stackSize} : undef);
107              
108             return $class->new(
109             id => $data->{id},
110             name => $data->{name},
111             slug => $data->{slug} // $data->{id},
112             category => $data->{category} // $data->{item_type},
113             rarity => $data->{rarity},
114             description => $data->{description},
115             stats => $stats,
116             weight => $weight,
117             stack_size => $stack_size,
118             base_value => $data->{baseValue} // $data->{value},
119             crafting_requirements => $data->{components} // [],
120             sold_by => $data->{soldBy} // [],
121             used_in => $data->{usedIn} // [],
122             compatible_with => $data->{compatibleWith} // [],
123             recycle_yield => $data->{recycleYield},
124             last_updated => $data->{lastUpdated} // $data->{updated_at},
125 132   33     4522 _raw => $data,
      66        
      66        
      100        
      50        
      50        
      50        
      66        
126             );
127             }
128              
129             1;
130              
131             __END__
132              
133             =pod
134              
135             =encoding UTF-8
136              
137             =head1 NAME
138              
139             WWW::MetaForge::ArcRaiders::Result::Item - Item result object
140              
141             =head1 VERSION
142              
143             version 0.002
144              
145             =head1 SYNOPSIS
146              
147             my $items = $api->items(search => 'Ferro');
148             for my $item (@$items) {
149             say $item->name . " (" . $item->rarity . ")";
150             say " Weight: " . $item->weight if $item->weight;
151             }
152              
153             =head1 DESCRIPTION
154              
155             Represents an item from the ARC Raiders game (weapons, mods, materials, consumables).
156              
157             =head2 id
158              
159             Item identifier (string slug).
160              
161             =head2 name
162              
163             Human-readable item name.
164              
165             =head2 slug
166              
167             URL-safe identifier.
168              
169             =head2 category
170              
171             Item type (e.g., "Weapon", "Material", "Consumable").
172              
173             =head2 rarity
174              
175             Item rarity (e.g., "Common", "Rare", "Legendary").
176              
177             =head2 description
178              
179             Item description text.
180              
181             =head2 stats
182              
183             HashRef of item statistics (damage, range, etc.).
184              
185             =head2 weight
186              
187             Item weight value.
188              
189             =head2 stack_size
190              
191             Maximum stack size for stackable items.
192              
193             =head2 base_value
194              
195             Base monetary value.
196              
197             =head2 crafting_requirements
198              
199             ArrayRef of crafting ingredients: C<[{ item => "Name", quantity => 5 }]>.
200              
201             =head2 sold_by
202              
203             ArrayRef of traders that sell this item.
204              
205             =head2 used_in
206              
207             ArrayRef of recipes/crafts using this item.
208              
209             =head2 compatible_with
210              
211             ArrayRef of compatible items.
212              
213             =head2 recycle_yield
214              
215             HashRef of materials from recycling.
216              
217             =head2 last_updated
218              
219             ISO timestamp of last data update.
220              
221             =head2 from_hashref
222              
223             my $item = WWW::MetaForge::ArcRaiders::Result::Item->from_hashref(\%data);
224              
225             Construct from API response. Handles field name mapping.
226              
227             =head1 SUPPORT
228              
229             =head2 Issues
230              
231             Please report bugs and feature requests on GitHub at
232             L<https://github.com/Getty/p5-www-metaforge/issues>.
233              
234             =head2 IRC
235              
236             You can reach Getty on C<irc.perl.org> for questions and support.
237              
238             =head1 CONTRIBUTING
239              
240             Contributions are welcome! Please fork the repository and submit a pull request.
241              
242             =head1 AUTHOR
243              
244             Torsten Raudssus <torsten@raudssus.de>
245              
246             =head1 COPYRIGHT AND LICENSE
247              
248             This software is copyright (c) 2026 by Torsten Raudssus.
249              
250             This is free software; you can redistribute it and/or modify it under
251             the same terms as the Perl 5 programming language system itself.
252              
253             =cut