Ordo/Command/Cal/List.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 137 CC 8 SCAR 34.0
CC
8
Cov
0%
execute
72.0
name
2.0
summary
2.0
CRAP 30.0
1 package App::Ordo::Command::Cal::List;
2 use Moo;
3 use feature qw(say);
4 use utf8;
5 use open ':std', ':utf8'; # Set STDOUT and STDERR to UTF-8
6 extends 'App::Ordo::Command::Base';
7 use POSIX qw(strftime);
8  
9 use Term::ANSIColor qw(colored);
10 use Text::Table::Tiny 1.02 qw(generate_table);
11  
12 sub name { "cal list" }
13 sub summary { "List all calendars and their cron expressions" }
14 sub usage { "[calendar-name]" }
15 sub aliases { ['cal ls'] }
16  
17 sub option_spec { {} }
18  
19 sub execute {
20 my ($self, $opt, $filter_name) = @_;
21  
22 my $res = $self->api->call('find_cal', {});
23 unless ($res->{success} && scalar @{ $res->{cals} }) {
24 say colored(["bold yellow"], "No calendars found");
25 return;
26 }
27  
28 my @cals = @{$res->{cals} || []};
29  
30 # Optional: filter by name
31 if ($filter_name) {
32 @cals = grep { ($_->{name} || '') eq $filter_name } @cals;
33 unless (@cals) {
34 say colored(["bold yellow"], "No calendar found with name: $filter_name");
35 return;
36 }
37 }
38  
39 say colored(["bold cyan"], "Calendars (" . scalar(@cals) . " found):\n");
40  
41 for my $cal (@cals) {
42 my $name = $cal->{name} || colored(["yellow"], "(unnamed id:$cal->{id})");
43 my $desc = $cal->{description} ? " - $cal->{description}" : "";
44 my $attached = $cal->{cluster_ids} && @{$cal->{cluster_ids}}
45 ? " (attached to " . scalar(@{$cal->{cluster_ids}}) . " clusters)"
46 : "";
47  
48 say colored(["bold white"], " $name$desc$attached");
49  
50 my $crons = $cal->{crons} || [];
51 if (@$crons) {
52 my $rows = [ [qw(ID CRON NEXT_START DESCRIPTION)] ];
53 for my $cron (@$crons) {
54 my $next = $cron->{next_start}
55 ? strftime("%Y-%m-%d %H:%M", localtime($cron->{next_start}))
56 : '-';
57 my $desc = $cron->{description} || $cron->{english} || '';
58 push @$rows, [
59 $cron->{id},
60 $cron->{name},
61 $next,
62 $desc,
63 ];
64 }
65 say generate_table(rows => $rows, header_row => 1, style => 'boxrule');
66 } else {
67 say " (no cron expressions)";
68 }
69 say ""; # spacing
70 }
71 }
72  
73 1;