| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Table; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1463
|
use 5.010; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
67
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
469
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Text::Table; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'headline' => ( |
|
10
|
|
|
|
|
|
|
is => 'rw', |
|
11
|
|
|
|
|
|
|
isa => 'Str', |
|
12
|
|
|
|
|
|
|
predicate => 'has_headline', |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'columns' => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
18
|
|
|
|
|
|
|
required => 1, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'data' => ( |
|
22
|
|
|
|
|
|
|
is => 'rw', |
|
23
|
|
|
|
|
|
|
isa => 'ArrayRef[HashRef]', |
|
24
|
|
|
|
|
|
|
traits => ['Array'], |
|
25
|
|
|
|
|
|
|
default => sub { [] }, |
|
26
|
|
|
|
|
|
|
handles => { |
|
27
|
|
|
|
|
|
|
rows => 'elements', |
|
28
|
|
|
|
|
|
|
add_row => 'push', |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub render_text { |
|
33
|
|
|
|
|
|
|
my ($self) = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @header = |
|
36
|
|
|
|
|
|
|
map { ($_,\"|") } |
|
37
|
|
|
|
|
|
|
@{$self->columns}; |
|
38
|
|
|
|
|
|
|
pop @header; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $table = Text::Table->new( |
|
41
|
|
|
|
|
|
|
@header |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
foreach my $row ($self->rows) { |
|
45
|
|
|
|
|
|
|
my @row; |
|
46
|
|
|
|
|
|
|
foreach my $column (@{$self->columns}) { |
|
47
|
|
|
|
|
|
|
my $column_key = lc($column); |
|
48
|
|
|
|
|
|
|
$column_key =~ s/\s+/_/g; |
|
49
|
|
|
|
|
|
|
push(@row,$row->{$column_key} // ''); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
$table->add(@row); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $content = ''; |
|
55
|
|
|
|
|
|
|
if ($self->has_headline) { |
|
56
|
|
|
|
|
|
|
$content .= '*'.uc($self->headline)."*\n"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
$content .= $table->title; |
|
59
|
|
|
|
|
|
|
$content .= $table->rule('-','+'); |
|
60
|
|
|
|
|
|
|
$content .= $table->body; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return $content; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub render_html { |
|
66
|
|
|
|
|
|
|
my ($self) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $rendered = '<div>'; |
|
69
|
|
|
|
|
|
|
$rendered .= '<h2>'.$self->headline.'</h2>' |
|
70
|
|
|
|
|
|
|
if $self->has_headline; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$rendered .= '<table witdh="100%"><thead><tr>'; |
|
73
|
|
|
|
|
|
|
foreach my $column (@{$self->columns}) { |
|
74
|
|
|
|
|
|
|
$rendered .= '<th>'.$column.'</th>'; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
$rendered .= '</tr></thead><tbody>'; |
|
77
|
|
|
|
|
|
|
foreach my $row ($self->rows) { |
|
78
|
|
|
|
|
|
|
$rendered .= '<tr>'; |
|
79
|
|
|
|
|
|
|
foreach my $column (@{$self->columns}) { |
|
80
|
|
|
|
|
|
|
my $column_key = lc($column); |
|
81
|
|
|
|
|
|
|
$column_key =~ s/\s+/_/g; |
|
82
|
|
|
|
|
|
|
$rendered .= '<td>'.($row->{$column_key} // '').'</td>'; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
$rendered .= '</tr>'; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
$rendered .= '</tbody></table></div>'; |
|
87
|
|
|
|
|
|
|
return $rendered; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
91
|
|
|
|
|
|
|
no Moose; |
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding utf8 |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Games::Lacuna::Task::Table -Â Simple table for reports |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $table = Games::Lacuna::Task::Table->new( |
|
103
|
|
|
|
|
|
|
headline => 'Some table', |
|
104
|
|
|
|
|
|
|
columns => ['Column 1','Column 2'], |
|
105
|
|
|
|
|
|
|
); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
foreach (@data) { |
|
108
|
|
|
|
|
|
|
$table->add_row({ |
|
109
|
|
|
|
|
|
|
column_1 => $_->[0], |
|
110
|
|
|
|
|
|
|
column_2 => $_->[1], |
|
111
|
|
|
|
|
|
|
}); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
say $table->render_text; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 ACCESSORS |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head3 headline |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Headline. [Optional] |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 columns |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Array of column names. [Required] |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head3 data |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Array of HashRefs. Usually not accessed directly. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 METHODS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head3 render_html |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Render table as HTML. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head3 render_text |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Render table as plain text. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 has_headline |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Checks if headline is set |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head3 add_row |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Add a new row. |