File Coverage

blib/lib/WWW/MetaForge/ArcRaiders/CLI/Cmd/Quests.pm
Criterion Covered Total %
statement 34 41 82.9
branch 6 12 50.0
condition 6 13 46.1
subroutine 5 5 100.0
pod 0 1 0.0
total 51 72 70.8


line stmt bran cond sub pod time code
1             package WWW::MetaForge::ArcRaiders::CLI::Cmd::Quests;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: List quests from the ARC Raiders API
4             our $VERSION = '0.002';
5 1     1   6699 use Moo;
  1         3  
  1         10  
6 1     1   552 use MooX::Cmd;
  1         2  
  1         12  
7 1     1   3544 use MooX::Options;
  1         2  
  1         10  
8 1     1   2696 use JSON::MaybeXS;
  1         3  
  1         615  
9              
10             option type => (
11             is => 'ro',
12             format => 's',
13             short => 't',
14             doc => 'Filter by quest type',
15             );
16              
17             option page => (
18             is => 'ro',
19             format => 'i',
20             short => 'p',
21             doc => 'Page number for pagination',
22             );
23              
24             option all => (
25             is => 'ro',
26             short => 'a',
27             doc => 'Fetch all pages',
28             );
29              
30             sub execute {
31 1     1 0 3977 my ($self, $args, $chain) = @_;
32 1         3 my $app = $chain->[0];
33              
34 1         2 my %params;
35 1 50       6 $params{type} = $self->type if $self->type;
36 1 50       5 $params{page} = $self->page if $self->page;
37              
38 1         3 my ($quests, $pagination);
39              
40 1 50       4 if ($self->all) {
41 0         0 $quests = $app->api->quests_all(%params);
42             } else {
43 1         37 my $result = $app->api->quests_paginated(%params);
44 1         9254 $quests = $result->{data};
45 1         5 $pagination = $result->{pagination};
46             }
47              
48 1 50       8 if ($app->json) {
49             print JSON::MaybeXS->new(utf8 => 1, pretty => 1)->encode(
50 0         0 [ map { $_->_raw } @$quests ]
  0         0  
51             );
52 0         0 return;
53             }
54              
55 1 50       5 if (!@$quests) {
56 0         0 print "No quests found.\n";
57 0         0 return;
58             }
59              
60 1         3 for my $quest (@$quests) {
61 1   50     6 my $name = $quest->name // 'Unknown';
62 1   50     6 my $id = $quest->id // '-';
63 1         63 printf "%-50s [%s]\n", $name, $id;
64             }
65              
66 1         4 my $shown = scalar(@$quests);
67 1 50 33     13 if ($pagination && !$self->all) {
68 1   50     5 my $total = $pagination->{total} // '?';
69 1   50     3 my $page_num = $pagination->{page} // 1;
70 1   50     7 my $total_pages = $pagination->{totalPages} // '?';
71 1         61 printf "\n%d quest(s) shown (page %d/%s, %s total). Use --all to fetch all pages.\n",
72             $shown, $page_num, $total_pages, $total;
73             } else {
74 0           printf "\n%d quest(s) found.\n", $shown;
75             }
76             }
77              
78             1;
79              
80             __END__
81              
82             =pod
83              
84             =encoding UTF-8
85              
86             =head1 NAME
87              
88             WWW::MetaForge::ArcRaiders::CLI::Cmd::Quests - List quests from the ARC Raiders API
89              
90             =head1 VERSION
91              
92             version 0.002
93              
94             =head1 SYNOPSIS
95              
96             arcraiders quests
97             arcraiders quests --type main
98             arcraiders quests --page 2
99             arcraiders quests --all
100             arcraiders quests --json
101              
102             =head1 DESCRIPTION
103              
104             Lists quests from the ARC Raiders API. By default, displays the first page
105             of quests. Use C<--all> to fetch all available quests across all pages.
106              
107             Quest information is displayed with the quest name and ID. When JSON output
108             is enabled (C<--json>), the raw API response data is returned.
109              
110             =head1 OPTIONS
111              
112             =head2 --type, -t
113              
114             Filter quests by type. Only quests matching the specified type will be returned.
115              
116             arcraiders quests --type main
117             arcraiders quests -t daily
118              
119             =head2 --page, -p
120              
121             Specify the page number for pagination. Defaults to page 1.
122              
123             arcraiders quests --page 2
124             arcraiders quests -p 3
125              
126             =head2 --all, -a
127              
128             Fetch all pages of quests. When enabled, pagination is handled automatically
129             and all quests are retrieved.
130              
131             arcraiders quests --all
132             arcraiders quests -a
133              
134             =head1 SUPPORT
135              
136             =head2 Issues
137              
138             Please report bugs and feature requests on GitHub at
139             L<https://github.com/Getty/p5-www-metaforge/issues>.
140              
141             =head2 IRC
142              
143             You can reach Getty on C<irc.perl.org> for questions and support.
144              
145             =head1 CONTRIBUTING
146              
147             Contributions are welcome! Please fork the repository and submit a pull request.
148              
149             =head1 AUTHOR
150              
151             Torsten Raudssus <torsten@raudssus.de>
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is copyright (c) 2026 by Torsten Raudssus.
156              
157             This is free software; you can redistribute it and/or modify it under
158             the same terms as the Perl 5 programming language system itself.
159              
160             =cut