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