File Coverage

blib/lib/WWW/MetaForge/ArcRaiders/CLI/Cmd/Events.pm
Criterion Covered Total %
statement 35 45 77.7
branch 9 20 45.0
condition 6 18 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 55 89 61.8


line stmt bran cond sub pod time code
1             package WWW::MetaForge::ArcRaiders::CLI::Cmd::Events;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Show event timers from the ARC Raiders API
4             our $VERSION = '0.002';
5 1     1   7201 use Moo;
  1         4  
  1         12  
6 1     1   604 use MooX::Cmd;
  1         3  
  1         11  
7 1     1   3901 use MooX::Options;
  1         2  
  1         10  
8 1     1   2922 use JSON::MaybeXS;
  1         2  
  1         660  
9              
10             option active => (
11             is => 'ro',
12             short => 'a',
13             doc => 'Show only currently active events',
14             );
15              
16             sub execute {
17 1     1 0 4000 my ($self, $args, $chain) = @_;
18 1         3 my $app = $chain->[0];
19              
20 1         39 my $events = $app->api->event_timers;
21              
22 1 50       159 if ($self->active) {
23 0         0 $events = [ grep { $_->is_active_now } @$events ];
  0         0  
24             }
25              
26             # Sort chronologically: active events first (by time until end), then upcoming (by time until start)
27             $events = [
28             sort {
29 1         8 my $a_active = $a->is_active_now;
  1         8  
30 1         6 my $b_active = $b->is_active_now;
31              
32             # Active events come first
33 1 50 33     9 return -1 if $a_active && !$b_active;
34 1 50 33     8 return 1 if !$a_active && $b_active;
35              
36             # Both active: sort by time until end
37 1 50       4 if ($a_active) {
38 0   0     0 return ($a->minutes_until_end // 9999) <=> ($b->minutes_until_end // 9999);
      0        
39             }
40              
41             # Both inactive: sort by time until start
42 1   50     8 return ($a->minutes_until_start // 9999) <=> ($b->minutes_until_start // 9999);
      50        
43             } @$events
44             ];
45              
46 1 50       10 if ($app->json) {
47             print JSON::MaybeXS->new(utf8 => 1, pretty => 1)->encode(
48 0         0 [ map { $_->_raw } @$events ]
  0         0  
49             );
50 0         0 return;
51             }
52              
53 1 50       5 if (!@$events) {
54 0         0 print "No events found.\n";
55 0         0 return;
56             }
57              
58 1         4 for my $event (@$events) {
59 2   50     15 my $name = $event->name // 'Unknown';
60 2   50     10 my $map = $event->map // '';
61 2 50       11 my $status = $event->is_active_now ? '[ACTIVE]' : '';
62 2         6 my $time_info = '';
63              
64 2 50       10 if ($event->is_active_now) {
65 0         0 my $remaining = $event->time_until_end;
66 0 0       0 $time_info = "ends in $remaining" if $remaining;
67             } else {
68 2         11 my $until = $event->time_until_start;
69 2 50       7 $time_info = "in $until" if $until;
70             }
71              
72 2         167 printf "%-30s %-15s %-10s %s\n", $name, $map, $status, $time_info;
73             }
74              
75 1         100 printf "\n%d event(s) found.\n", scalar(@$events);
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::Events - Show event timers from the ARC Raiders API
89              
90             =head1 VERSION
91              
92             version 0.002
93              
94             =head1 SYNOPSIS
95              
96             arcraiders events
97             arcraiders events --active
98             arcraiders events -a
99              
100             # JSON output
101             arcraiders --json events
102              
103             =head1 DESCRIPTION
104              
105             This command displays event timers from the ARC Raiders API. Events are shown
106             in chronological order: currently active events appear first (sorted by time
107             remaining until end), followed by upcoming events (sorted by time until start).
108              
109             For each event, the output displays:
110              
111             =over 4
112              
113             =item * Event name
114              
115             =item * Map name (if available)
116              
117             =item * Status indicator C<[ACTIVE]> for running events
118              
119             =item * Time information (either "ends in X" or "in X")
120              
121             =back
122              
123             =head1 OPTIONS
124              
125             =head2 --active, -a
126              
127             Show only currently active events. This filters out upcoming events that
128             haven't started yet.
129              
130             =head1 SUPPORT
131              
132             =head2 Issues
133              
134             Please report bugs and feature requests on GitHub at
135             L<https://github.com/Getty/p5-www-metaforge/issues>.
136              
137             =head2 IRC
138              
139             You can reach Getty on C<irc.perl.org> for questions and support.
140              
141             =head1 CONTRIBUTING
142              
143             Contributions are welcome! Please fork the repository and submit a pull request.
144              
145             =head1 AUTHOR
146              
147             Torsten Raudssus <torsten@raudssus.de>
148              
149             =head1 COPYRIGHT AND LICENSE
150              
151             This software is copyright (c) 2026 by Torsten Raudssus.
152              
153             This is free software; you can redistribute it and/or modify it under
154             the same terms as the Perl 5 programming language system itself.
155              
156             =cut