line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Mattermost::Helper::Table; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
177138
|
use Moo; |
|
1
|
|
|
|
|
7034
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
2145
|
use Types::Standard qw(ArrayRef Enum Str); |
|
1
|
|
|
|
|
71090
|
|
|
1
|
|
|
|
|
16
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has alignment => (is => 'ro', isa => ArrayRef[Enum[ qw(l r c) ]], required => 0); |
11
|
|
|
|
|
|
|
has values => (is => 'ro', isa => ArrayRef, required => 1); |
12
|
|
|
|
|
|
|
has headers => (is => 'ro', isa => ArrayRef, required => 1); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has _headers => (is => 'ro', isa => Str, lazy => 1, builder => '_build__headers'); |
15
|
|
|
|
|
|
|
has table => (is => 'ro', isa => Str, lazy => 1, builder => '_build_table'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has divider => (is => 'ro', isa => Str, default => q{|}); |
18
|
|
|
|
|
|
|
has align_l => (is => 'ro', isa => Str, default => ':----|'); |
19
|
|
|
|
|
|
|
has align_r => (is => 'ro', isa => Str, default => '----:|'); |
20
|
|
|
|
|
|
|
has align_c => (is => 'ro', isa => Str, default => ':---:|'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _build__headers { |
25
|
2
|
|
|
2
|
|
18
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
5
|
my $headers = q{}; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
3
|
foreach my $h (@{$self->headers}) { |
|
2
|
|
|
|
|
13
|
|
30
|
6
|
|
|
|
|
26
|
$headers .= sprintf '%s %s', $self->divider, $h; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
8
|
$headers .= $self->divider."\n".$self->divider; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
5
|
for (my $i = 0; $i < scalar @{$self->headers}; $i++) { |
|
8
|
|
|
|
|
21
|
|
36
|
6
|
|
100
|
|
|
30
|
my $al = $self->alignment && $self->alignment->[$i] || 'l'; |
37
|
6
|
|
|
|
|
10
|
my $attr = "align_${al}"; |
38
|
|
|
|
|
|
|
|
39
|
6
|
|
|
|
|
18
|
$headers .= $self->$attr; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
32
|
return $headers; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _build_table { |
46
|
2
|
|
|
2
|
|
12866
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
34
|
my $table = $self->_headers."\n"; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
52
|
foreach my $v (@{$self->values}) { |
|
2
|
|
|
|
|
9
|
|
51
|
8
|
|
|
|
|
13
|
$table .= $self->divider; |
52
|
8
|
|
|
|
|
14
|
$table .= join $self->divider, @{$v}; |
|
8
|
|
|
|
|
17
|
|
53
|
8
|
|
|
|
|
28
|
$table .= $self->divider."\n"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
42
|
return $table; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=encoding UTF-8 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
WebService::Mattermost::Helper::Table - Markdown table generator. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 VERSION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
version 0.26 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Format text as tables for Mattermost. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 USAGE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use WebService::Mattermost::Helper::Table; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $helper = WebService::Mattermost::Helper::Table->new({ |
86
|
|
|
|
|
|
|
alignment => [ qw(r l l) ], |
87
|
|
|
|
|
|
|
headers => [ 'ID', 'Title', 'Date Created' ], |
88
|
|
|
|
|
|
|
values => [ |
89
|
|
|
|
|
|
|
[ 1, 'First row', '2018-09-16' ], |
90
|
|
|
|
|
|
|
[ 2, 'Second row', '2018-09-17' ], |
91
|
|
|
|
|
|
|
[ 3, 'Third row', '2018-09-17' ], |
92
|
|
|
|
|
|
|
], |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
print $helper->table; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item L<Mattermost Markdown|https://docs.mattermost.com/help/messaging/formatting-text.html#tables> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 AUTHOR |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Mike Jones <mike@netsplit.org.uk> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Mike Jones. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This is free software, licensed under: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The MIT (X11) License |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|