Ordo/Command/Cal/Show.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 132 CC 9 SCAR 38.3
CC
9
Cov
0%
execute
90.0
name
2.0
summary
2.0
CRAP 46.0
1 package App::Ordo::Command::Cal::Show;
2 use Moo;
3 extends 'App::Ordo::Command::Base';
4 use feature qw(say);
5 use POSIX qw(strftime);
6  
7 use Term::ANSIColor qw(colored);
8 use Text::Table::Tiny 1.02 qw(generate_table);
9  
10 sub name { "cal show" }
11 sub summary { "Show detailed information about a calendar" }
12 sub usage { "<calendar-name>" }
13  
14 sub option_spec { {} }
15  
16 sub execute {
17 my ($self, $opt, $cal_name) = @_;
18  
19 unless ($cal_name) {
20 say colored(["bold red"], "Usage: cal show <calendar-name>");
21 return;
22 }
23  
24 my $res = $self->api->call('find_cal', { name => $cal_name });
25  
26 unless ($res->{success}) {
27 say colored(["bold red"], "Calendar not found: $cal_name");
28 say " " . ($res->{message} || '');
29 return;
30 }
31  
32 my ($cal) = grep { ($_->{name} || '') eq $cal_name } @{$res->{cals} || []};
33 unless ($cal) {
34 say colored(["bold red"], "Calendar '$cal_name' not found");
35 return;
36 }
37  
38 my $name = $cal->{name} || colored(["yellow"], "(unnamed id:$cal->{id})");
39 my $tz = $cal->{tz} ? "$cal->{tz}" : "";
40 my $desc = $cal->{description} ? " - $cal->{description}" : "";
41 my $attached = $cal->{cluster_ids} && @{$cal->{cluster_ids}}
42 ? join(", ", @{$cal->{cluster_ids}})
43 : "(not attached)";
44  
45 say colored(["bold cyan"], "Calendar: $name$desc");
46 say colored(["bold cyan"], "TimeZone: $tz");
47 say colored(["bold cyan"], "Attached: $attached\n");
48  
49 my $crons = $cal->{crons} || [];
50 if (@$crons) {
51 my $rows = [ [qw(ID CRON NEXT_START DESCRIPTION)] ];
52 for my $cron (@$crons) {
53 my $next = $cron->{next_start}
54 ? strftime("%Y-%m-%d %H:%M", localtime($cron->{next_start}))
55 : '-';
56 my $desc = $cron->{description} || $cron->{english} || '';
57 push @$rows, [ $cron->{id}, $cron->{name}, $next, $desc ];
58 }
59 say generate_table(rows => $rows, header_row => 1, style => 'boxrule');
60 } else {
61 say colored(["yellow"], " (no cron expressions defined)");
62 }
63 }
64  
65 1;