File Coverage

blib/lib/WWW/MetaForge/ArcRaiders/CLI/Cmd/Event.pm
Criterion Covered Total %
statement 52 67 77.6
branch 13 32 40.6
condition 4 14 28.5
subroutine 7 7 100.0
pod 0 1 0.0
total 76 121 62.8


line stmt bran cond sub pod time code
1             package WWW::MetaForge::ArcRaiders::CLI::Cmd::Event;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Show details for a single event timer
4             our $VERSION = '0.002';
5 1     1   7619 use Moo;
  1         3  
  1         12  
6 1     1   569 use MooX::Cmd;
  1         3  
  1         13  
7 1     1   3707 use MooX::Options;
  1         2  
  1         11  
8 1     1   2796 use JSON::MaybeXS;
  1         4  
  1         1085  
9              
10             option map => (
11             is => 'ro',
12             format => 's',
13             short => 'm',
14             doc => 'Filter by map name (e.g., dam, spaceport)',
15             );
16              
17             sub execute {
18 2     2 0 4993 my ($self, $args, $chain) = @_;
19 2         6 my $app = $chain->[0];
20              
21 2         5 my $event_name = $args->[0];
22 2 100       10 unless ($event_name) {
23 1         54 print "Usage: arcraiders event <name> [--map <map>]\n";
24 1         32 print "Example: arcraiders event \"Cold Snap\" --map dam\n";
25 1         9 return;
26             }
27              
28             # Events don't have IDs, so search by name (and optionally map)
29 1         66 my $events = $app->api->event_timers;
30              
31             # Filter by name first
32             my @matches = grep {
33 1 50       5 $_->name && lc($_->name) eq lc($event_name)
  2         69  
34             } @$events;
35              
36             # Try partial match if exact fails
37 1 50       7 if (!@matches) {
38             @matches = grep {
39 0 0       0 $_->name && $_->name =~ /\Q$event_name\E/i
  0         0  
40             } @$events;
41             }
42              
43             # Filter by map if specified
44 1 50 33     6 if ($self->map && @matches) {
45             @matches = grep {
46 0 0       0 $_->map && lc($_->map) eq lc($self->map)
  0         0  
47             } @matches;
48             }
49              
50 1         3 my $event;
51 1 50       13 if (@matches == 1) {
    0          
52 1         3 $event = $matches[0];
53             } elsif (@matches > 1) {
54 0         0 print "Multiple events match '$event_name':\n";
55 0         0 for my $m (@matches) {
56 0   0     0 printf " %s (%s)\n", $m->name // 'Unknown', $m->map // 'all';
      0        
57             }
58 0         0 print "\nUse --map to specify: arcraiders event \"$event_name\" --map <map>\n";
59 0         0 return;
60             }
61              
62 1 50       4 unless ($event) {
63 0         0 print "Event '$event_name' not found.\n";
64 0         0 return;
65             }
66              
67 1 50       26 if ($app->json) {
68 0         0 print JSON::MaybeXS->new(utf8 => 1, pretty => 1)->encode($event->_raw);
69 0         0 return;
70             }
71              
72 1         5 _print_event_details($event);
73             }
74              
75             sub _print_event_details {
76 1     1   3 my ($event) = @_;
77              
78 1         64 print "=" x 60, "\n";
79 1   50     83 printf "%s\n", $event->name // 'Unknown';
80 1         23 print "=" x 60, "\n";
81              
82 1   50     12 _print_field("Map", $event->map // 'All Maps');
83 1         40 _print_field("Icon", $event->icon);
84              
85             # Current status
86 1 50       9 my $status = $event->is_active_now ? "ACTIVE" : "Inactive";
87 1         8 _print_field("Status", $status);
88              
89 1 50       8 if ($event->is_active_now) {
90 0         0 my $ends_in = $event->time_until_end;
91 0 0       0 _print_field("Ends in", $ends_in) if $ends_in;
92             } else {
93 1         6 my $starts_in = $event->time_until_start;
94 1 50       6 _print_field("Starts in", $starts_in) if $starts_in;
95             }
96              
97 1 50 33     8 if ($event->times && @{$event->times}) {
  1         6  
98 1         37 print "\nSchedule (UTC):\n";
99 1         4 my @sorted = sort { $a->start <=> $b->start } @{$event->times};
  3         196  
  1         10  
100 1         126 for my $slot (@sorted) {
101 3         243 printf " %s - %s\n", $slot->start->strftime('%H:%M'), $slot->end->strftime('%H:%M');
102             }
103             }
104             }
105              
106             sub _print_field {
107 3     3   10 my ($label, $value) = @_;
108 3 50       11 return unless defined $value;
109 3         94 printf "%-15s %s\n", "$label:", $value;
110             }
111              
112             1;
113              
114             __END__
115              
116             =pod
117              
118             =encoding UTF-8
119              
120             =head1 NAME
121              
122             WWW::MetaForge::ArcRaiders::CLI::Cmd::Event - Show details for a single event timer
123              
124             =head1 VERSION
125              
126             version 0.002
127              
128             =head1 SYNOPSIS
129              
130             # Show details for an event by name
131             arcraiders event "Cold Snap"
132              
133             # Filter by specific map
134             arcraiders event "Cold Snap" --map dam
135              
136             # Partial name matching
137             arcraiders event "Cold"
138              
139             # JSON output
140             arcraiders --json event "Cold Snap"
141              
142             =head1 DESCRIPTION
143              
144             Display detailed information about a single event timer. Searches for events by
145             name using exact match first, falling back to partial/case-insensitive match if
146             no exact match is found.
147              
148             The detail view shows:
149              
150             =over 4
151              
152             =item * Event name and map
153              
154             =item * Current status (active/inactive)
155              
156             =item * Time until start or end
157              
158             =item * Description with word wrapping
159              
160             =item * Complete schedule with time slots
161              
162             =item * Active days of the week
163              
164             =back
165              
166             If multiple events match the search criteria, displays a list of matches and
167             suggests using C<--map> to narrow results.
168              
169             =head1 OPTIONS
170              
171             =head2 --map, -m
172              
173             Filter results by map name. Useful when the same event appears on multiple maps.
174              
175             arcraiders event "Cold Snap" --map dam
176             arcraiders event "Cold Snap" -m spaceport
177              
178             =head1 SUPPORT
179              
180             =head2 Issues
181              
182             Please report bugs and feature requests on GitHub at
183             L<https://github.com/Getty/p5-www-metaforge/issues>.
184              
185             =head2 IRC
186              
187             You can reach Getty on C<irc.perl.org> for questions and support.
188              
189             =head1 CONTRIBUTING
190              
191             Contributions are welcome! Please fork the repository and submit a pull request.
192              
193             =head1 AUTHOR
194              
195             Torsten Raudssus <torsten@raudssus.de>
196              
197             =head1 COPYRIGHT AND LICENSE
198              
199             This software is copyright (c) 2026 by Torsten Raudssus.
200              
201             This is free software; you can redistribute it and/or modify it under
202             the same terms as the Perl 5 programming language system itself.
203              
204             =cut