line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
27
|
use 5.14.0; |
|
2
|
|
|
1
|
|
8
|
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
4
|
|
2
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
1
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
1
|
|
4
|
|
|
2
|
|
|
|
|
255
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Pod::Elemental::Transformer::Splint::MethodRenderer::HtmlDefault; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.1003'; # VERSION |
8
|
|
|
|
|
|
|
# ABSTRACT: Default html method renderer |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
16
|
use Moose; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
28
|
|
11
|
3
|
|
|
3
|
|
19665
|
use Path::Tiny; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
174
|
|
12
|
3
|
|
|
3
|
|
17
|
use Pod::Simple::XHTML; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
98
|
|
13
|
3
|
|
|
3
|
|
2596
|
use List::AllUtils qw/any uniq/; |
|
3
|
|
|
|
|
13351
|
|
|
3
|
|
|
|
|
520
|
|
14
|
3
|
|
|
3
|
|
21
|
use syntax 'qs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
22
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Pod::Elemental::Transformer::Splint::MethodRenderer'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub render_method { |
19
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
20
|
2
|
|
|
|
|
3
|
my $data = shift; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
5
|
my $positional_params = $data->{'positional_params'}; |
23
|
2
|
|
|
|
|
5
|
my $named_params = $data->{'named_params'}; |
24
|
2
|
|
|
|
|
4
|
my $return_types = $data->{'return_types'}; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
6
|
my @html = (''); |
27
|
2
|
|
|
|
|
4
|
my $table_style = q{style="margin-bottom: 10px; margin-left: 10px; border-collapse: bollapse;" cellpadding="0" cellspacing="0"}; |
28
|
2
|
|
|
|
|
3
|
my $th_style = q{style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color:}; |
29
|
2
|
|
|
|
|
3
|
my $tr_style = q{style="vertical-align: top;"}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
4
|
my $method_doc = undef; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
24
|
my $colspan = $self->get_colspan([ @$positional_params, @$named_params, @$return_types]); |
34
|
|
|
|
|
|
|
|
35
|
2
|
50
|
|
|
|
14
|
if(scalar @$positional_params) { |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
11
|
my $fake_colspan = join '' => (qq{<td $th_style #eee8e8;"> </td>} x ($colspan - 1)); |
38
|
2
|
|
|
|
|
10
|
push @html => qq{<tr $tr_style><td $th_style #eee8e8;">Positional parameters</td>$fake_colspan</tr>}; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
5
|
foreach my $param (@$positional_params) { |
41
|
|
|
|
|
|
|
|
42
|
4
|
50
|
|
|
|
13
|
$method_doc = $param->{'method_doc'} if defined $param->{'method_doc'}; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
9
|
push @html => "<tr $tr_style>"; |
45
|
4
|
|
|
|
|
23
|
push @html => $self->make_cell_with_border(nowrap => 1, text => $self->parse_pod(sprintf 'C<%s>', $param->{'name'})); |
46
|
4
|
|
|
|
|
13
|
push @html => $self->make_cell_with_border(nowrap => 2, text => $param->{'type'}); |
47
|
4
|
100
|
|
|
|
23
|
push @html => $self->make_cell_with_border(nowrap => 3, text => (join ', ' => $param->{'required_text'}, $param->{'is_required'} ? defined $param->{'default'} ? $self->param_default_text($param) : () : $self->param_default_text($param))); |
|
|
50
|
|
|
|
|
|
48
|
4
|
|
|
|
|
14
|
push @html => $self->make_cell_with_border(nowrap => 4, text => $self->param_trait_text($param)); |
49
|
4
|
|
|
|
|
10
|
push @html => $self->make_cell_without_border(nowrap => 0, text => join '' => map { "$_<br />" } @{ $param->{'docs'} }); |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
9
|
|
50
|
|
|
|
|
|
|
|
51
|
4
|
|
|
|
|
10
|
push @html => '</tr>'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
2
|
100
|
|
|
|
7
|
if(scalar @$named_params) { |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
13
|
my $fake_colspan = join '' => (qq{<td $th_style #e8eee8;"> </td>} x ($colspan - 1)); |
57
|
1
|
|
|
|
|
4
|
push @html => qq{<tr $tr_style><td $th_style #e8eee8;">Named parameters</td>$fake_colspan</tr>}; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
2
|
foreach my $param (@$named_params) { |
60
|
3
|
100
|
|
|
|
9
|
$method_doc = $param->{'method_doc'} if defined $param->{'method_doc'}; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
7
|
push @html => "<tr $tr_style>"; |
63
|
3
|
|
|
|
|
18
|
push @html => $self->make_cell_with_border(nowrap => 5, text => $self->parse_pod(sprintf 'C<%s =E<gt> %s>', $param->{'name_without_sigil'}, '$value')); |
64
|
3
|
|
|
|
|
9
|
push @html => $self->make_cell_with_border(nowrap => 6, text => $param->{'type'}); |
65
|
3
|
50
|
33
|
|
|
22
|
push @html => $self->make_cell_with_border(nowrap => 7, text => join ', ' => $param->{'required_text'}, $param->{'is_required'} && defined $param->{'default'} ? $self->param_default_text($param) : $param->{'is_required'} ? () : $self->param_default_text($param)); |
|
|
50
|
|
|
|
|
|
66
|
3
|
|
|
|
|
11
|
push @html => $self->make_cell_with_border(nowrap => 8, text => $self->param_trait_text($param)); |
67
|
3
|
|
|
|
|
6
|
push @html => $self->make_cell_without_border(nowrap => 0, text => join '<br />' => @{ $param->{'docs'} }); |
|
3
|
|
|
|
|
10
|
|
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
8
|
push @html => '</tr>'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
2
|
100
|
|
|
|
6
|
if(scalar @$return_types) { |
73
|
1
|
|
|
|
|
5
|
my $fake_colspan = join '' => (qq{<td $th_style #e8e8ee;"> </td>} x ($colspan - 1)); |
74
|
1
|
|
|
|
|
10
|
push @html => qq{<tr $tr_style><td $th_style #e8e8ee;">Returns</td>$fake_colspan</tr>}; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
foreach my $return_type (@$return_types) { |
77
|
1
|
50
|
|
|
|
4
|
$method_doc = $return_type->{'method_doc'} if defined $return_type->{'method_doc'}; |
78
|
1
|
|
|
|
|
2
|
my $has_doc = scalar @{ $return_type->{'docs'} }; |
|
1
|
|
|
|
|
3
|
|
79
|
1
|
50
|
|
|
|
4
|
my $return_colspan = $has_doc ? $colspan - 1 : $colspan; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
push @html => qq{<tr $tr_style>}; |
82
|
|
|
|
|
|
|
push @html => $has_doc ? $self->make_cell_with_border(nowrap => 0, colspan => $return_colspan, text => $return_type->{'type'}) |
83
|
1
|
50
|
|
|
|
6
|
: $self->make_cell_without_border(nowrap => 0, colspan => $return_colspan, text => $return_type->{'type'}) |
84
|
|
|
|
|
|
|
; |
85
|
1
|
|
|
|
|
3
|
push @html => $self->make_cell_without_border(nowrap => 0, text => join '<br />' => @{ $return_type->{'docs'} }); |
|
1
|
|
|
|
|
5
|
|
86
|
1
|
|
|
|
|
4
|
push @html => '</tr>'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
2
|
50
|
|
|
|
6
|
if(scalar @html) { |
90
|
2
|
|
|
|
|
11
|
unshift @html => '<!-- -->', qq{<table $table_style>}; |
91
|
2
|
|
|
|
|
3
|
push @html => '</table>'; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
100
|
|
|
10
|
my $content = sprintf qs{ |
|
65
|
|
|
|
|
1757
|
|
95
|
|
|
|
|
|
|
=begin HTML |
96
|
2
|
|
|
|
|
101
|
|
97
|
|
|
|
|
|
|
<p>%s</p> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
%s |
100
|
2
|
|
|
2
|
0
|
4
|
|
101
|
2
|
|
|
|
|
3
|
=end HTML |
102
|
|
|
|
|
|
|
}, $method_doc // '', join "\n" => map { qqs{$_} } @html; |
103
|
2
|
50
|
|
8
|
|
14
|
|
|
2
|
50
|
|
|
|
10
|
|
|
2
|
50
|
|
|
|
13
|
|
|
8
|
|
|
|
|
19
|
|
104
|
|
|
|
|
|
|
return $content; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_colspan { |
108
|
|
|
|
|
|
|
my $self = shift; |
109
|
|
|
|
|
|
|
my $params = shift; |
110
|
7
|
|
|
7
|
0
|
13
|
|
111
|
7
|
|
|
|
|
9
|
return (any { defined $_->{'docs'} && scalar @{ $_->{'docs'} } } @$params) ? (any { ref $_->{'docs'} eq 'HASH' } @$params) ? 6 |
112
|
|
|
|
|
|
|
: 5 |
113
|
7
|
100
|
|
|
|
9
|
: 4 |
|
11
|
|
|
|
|
42
|
|
|
7
|
|
|
|
|
15
|
|
114
|
|
|
|
|
|
|
; |
115
|
7
|
100
|
|
|
|
33
|
} |
116
|
1
|
50
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
117
|
|
|
|
|
|
|
sub param_trait_text { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
my $param = shift; |
120
|
7
|
|
|
7
|
0
|
11
|
|
121
|
7
|
|
|
|
|
8
|
my @traits = grep { $_ ne 'doc' && $_ ne 'optional' } @{ $self->param_trait_list($param) }; |
122
|
|
|
|
|
|
|
|
123
|
7
|
|
|
|
|
8
|
return undef if !scalar @traits; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
58
|
|
|
7
|
|
|
|
|
16
|
|
124
|
|
|
|
|
|
|
return join ', ' => map { $_ eq 'slurpy' ? $_ : sprintf '<a href="https://metacpan.org/pod/Kavorka/TraitFor/Parameter/%s">$_</a>', $_ } @traits; |
125
|
7
|
|
|
|
|
22
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub param_trait_list { |
128
|
|
|
|
|
|
|
my $self = shift; |
129
|
|
|
|
|
|
|
my $param = shift; |
130
|
4
|
|
|
4
|
0
|
6
|
|
131
|
4
|
|
|
|
|
4
|
my $trait_list = [ uniq sort map { keys %{ $_ } } @{ $param->{'traits'} } ]; |
132
|
|
|
|
|
|
|
|
133
|
4
|
100
|
|
|
|
15
|
return $trait_list; |
134
|
3
|
100
|
66
|
|
|
13
|
|
|
1
|
|
|
|
|
11
|
|
135
|
2
|
50
|
|
|
|
7
|
} |
136
|
|
|
|
|
|
|
|
137
|
2
|
50
|
66
|
|
|
10
|
sub param_default_text { |
|
1
|
|
|
|
|
6
|
|
138
|
2
|
100
|
|
|
|
19
|
my $self = shift; |
139
|
|
|
|
|
|
|
my $param = shift; |
140
|
1
|
50
|
|
|
|
4
|
|
141
|
1
|
50
|
|
|
|
8
|
return q{<span style="color: #999;">no default</span>} if !defined $param->{'default'}; |
142
|
|
|
|
|
|
|
return $self->parse_pod(sprintf q(default C<%s { }>), $param->{'default_when'}) if ref $param->{'default'} eq 'HASH' && scalar keys %{ $param->{'default'} } == 0; |
143
|
|
|
|
|
|
|
return $self->parse_pod(sprintf q(default C<%s hashref>), $param->{'default_when'}) if ref $param->{'default'} eq 'HASH'; |
144
|
|
|
|
|
|
|
|
145
|
8
|
|
|
8
|
0
|
10
|
return $self->parse_pod(sprintf q(default C<%s [ ]>), $param->{'default_when'}) if ref $param->{'default'} eq 'ARRAY' && scalar @{ $param->{'default'} } == 0; |
146
|
8
|
|
|
|
|
19
|
return $self->parse_pod(sprintf q(default C<%s arrayref>), $param->{'default_when'}) if ref $param->{'default'} eq 'ARRAY'; |
147
|
8
|
50
|
|
|
|
18
|
|
148
|
|
|
|
|
|
|
return $self->parse_pod(sprintf q{default C<%s coderef>}, $param->{'default_when'}) if ref $param->{'default'} eq 'CODE'; |
149
|
8
|
|
|
|
|
14
|
return $self->parse_pod(sprintf q{default C<%s %s>}, $param->{'default_when'}, $param->{'default'} eq '' ? "''" : $param->{'default'}); |
150
|
8
|
|
|
|
|
16
|
} |
151
|
|
|
|
|
|
|
|
152
|
8
|
|
|
|
|
26
|
sub make_cell_without_border { |
153
|
|
|
|
|
|
|
my $self = shift; |
154
|
|
|
|
|
|
|
my($text, $nowrap, $colspan) = $self->fix_cell_args(@_); |
155
|
29
|
|
|
29
|
0
|
42
|
$text = defined $text ? $text : ''; |
156
|
|
|
|
|
|
|
|
157
|
29
|
|
|
|
|
63
|
my $style = qq{style="padding: 3px 6px; vertical-align: top; $nowrap border-bottom: 1px solid #eee;"}; |
158
|
29
|
100
|
|
|
|
60
|
my $colspans = join '' => (qq{<td $style> </td>} x $colspan); |
159
|
29
|
100
|
|
|
|
48
|
|
160
|
|
|
|
|
|
|
return qq{<td $style>$text</td>$colspans}; |
161
|
29
|
|
|
|
|
58
|
} |
162
|
29
|
|
|
|
|
61
|
sub make_cell_with_border { |
163
|
|
|
|
|
|
|
my $self = shift; |
164
|
29
|
|
|
|
|
106
|
|
165
|
|
|
|
|
|
|
my($text, $nowrap, $colspan) = $self->fix_cell_args(@_); |
166
|
|
|
|
|
|
|
my $padding = defined $text ? ' padding: 3px 6px;' : ''; |
167
|
|
|
|
|
|
|
$text = defined $text ? $text : ''; |
168
|
37
|
|
|
37
|
0
|
48
|
|
169
|
37
|
|
|
|
|
91
|
my $style = qq{style="vertical-align: top; border-right: 1px solid #eee;$nowrap $padding border-bottom: 1px solid #eee;"}; |
170
|
|
|
|
|
|
|
my $colspans = join '' => (qq{<td $style> </td>} x $colspan); |
171
|
37
|
|
|
|
|
54
|
|
172
|
37
|
100
|
|
|
|
79
|
return qq{<td $style>$text</td>$colspans}; |
173
|
37
|
100
|
|
|
|
75
|
} |
174
|
|
|
|
|
|
|
|
175
|
37
|
|
|
|
|
108
|
sub fix_cell_args { |
176
|
|
|
|
|
|
|
my $self = shift; |
177
|
|
|
|
|
|
|
my %args = @_; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
my $text = $args{'text'}; |
180
|
|
|
|
|
|
|
my $nowrap = !$args{'nowrap'} ? '' : ' white-space: nowrap;'; |
181
|
|
|
|
|
|
|
my $colspan = !exists $args{'colspan'} ? 0 : $args{'colspan'} - 1; # Since we add cells *after* the current one. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
return ($text, $nowrap, $colspan); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
__END__ |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=pod |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=encoding UTF-8 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 NAME |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Pod::Elemental::Transformer::Splint::MethodRenderer::HtmlDefault - Default html method renderer |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 VERSION |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Version 0.1003, released 2016-01-11. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 SOURCE |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L<https://github.com/Csson/p5-Pod-Elemental-Transformer-Splint> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 HOMEPAGE |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L<https://metacpan.org/release/Pod-Elemental-Transformer-Splint> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 AUTHOR |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Erik Carlsson <info@code301.com> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Erik Carlsson. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
219
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |