line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::EmpireReport; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1563
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
65
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Module::Pluggable |
7
|
1
|
|
|
|
|
8
|
search_path => ['Games::Lacuna::Task::Report'], |
8
|
1
|
|
|
1
|
|
938
|
sub_name => 'all_reports'; |
|
1
|
|
|
|
|
14612
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
609
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
12
|
|
|
|
|
|
|
with 'Games::Lacuna::Task::Role::Notify',all_reports(); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Games::Lacuna::Task::Table; |
15
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
16
|
|
|
|
|
|
|
use Games::Lacuna::Task::Utils qw(pretty_dump class_to_name); |
17
|
|
|
|
|
|
|
use IO::Interactive qw(is_interactive); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
subtype 'Lacuna::Task::Type::Output' |
20
|
|
|
|
|
|
|
=> as enum([qw(email stdout)]) |
21
|
|
|
|
|
|
|
=> message { "Not a valid output type '$_'" }; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'report' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
26
|
|
|
|
|
|
|
documentation => 'Specifies which sub-reports to include in the empire report', |
27
|
|
|
|
|
|
|
default => sub { |
28
|
|
|
|
|
|
|
[ map { class_to_name($_) } all_reports() ] |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'output' => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'Lacuna::Task::Type::Output', |
35
|
|
|
|
|
|
|
documentation => 'Specifies how the report should be presented to the user [Options: email, stdout]', |
36
|
|
|
|
|
|
|
default => sub { |
37
|
|
|
|
|
|
|
if (is_interactive) { |
38
|
|
|
|
|
|
|
return 'stdout'; |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
return 'email'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub description { |
46
|
|
|
|
|
|
|
return q[Generate an informative empire status report]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub run { |
50
|
|
|
|
|
|
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $empire_name = $self->empire_name; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $report_html = join '',<DATA>; |
55
|
|
|
|
|
|
|
my @report_tables; |
56
|
|
|
|
|
|
|
foreach my $report (@{$self->report}) { |
57
|
|
|
|
|
|
|
my $method = 'report_'.$report; |
58
|
|
|
|
|
|
|
foreach my $report_data ($self->$method()) { |
59
|
|
|
|
|
|
|
push(@report_tables,$report_data); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
given ($self->output) { |
64
|
|
|
|
|
|
|
when ('email') { |
65
|
|
|
|
|
|
|
my $report_content = |
66
|
|
|
|
|
|
|
join "\n", |
67
|
|
|
|
|
|
|
map { $_->render_html() } |
68
|
|
|
|
|
|
|
@report_tables; |
69
|
|
|
|
|
|
|
$report_html =~ s/\@REPORT\@/$report_content/g; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$self->notify( |
72
|
|
|
|
|
|
|
"[$empire_name] Status report", |
73
|
|
|
|
|
|
|
$report_html |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
when ('stdout') { |
77
|
|
|
|
|
|
|
my $report_content = |
78
|
|
|
|
|
|
|
join "\n", |
79
|
|
|
|
|
|
|
map { $_->render_text() } |
80
|
|
|
|
|
|
|
@report_tables; |
81
|
|
|
|
|
|
|
say $report_content; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
87
|
|
|
|
|
|
|
no Moose; |
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__DATA__ |
91
|
|
|
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
92
|
|
|
|
|
|
|
<html> |
93
|
|
|
|
|
|
|
<head> |
94
|
|
|
|
|
|
|
<title>Empire Report</title> |
95
|
|
|
|
|
|
|
<style type="text/css"> |
96
|
|
|
|
|
|
|
th { |
97
|
|
|
|
|
|
|
border-bottom: 2px solid; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
tr { |
100
|
|
|
|
|
|
|
border-bottom: 1px solid grey; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
</style> |
103
|
|
|
|
|
|
|
</head> |
104
|
|
|
|
|
|
|
<body> |
105
|
|
|
|
|
|
|
@REPORT@ |
106
|
|
|
|
|
|
|
</body> |
107
|
|
|
|
|
|
|
</html> |