line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package APISchema::Generator::Markdown::ExampleFormatter; |
2
|
3
|
|
|
3
|
|
48
|
use 5.014; |
|
3
|
|
|
|
|
10
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
52
|
|
4
|
3
|
|
|
3
|
|
29
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
77
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# lib |
7
|
3
|
|
|
3
|
|
351
|
use APISchema::Generator::Markdown::Formatter qw(json); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
176
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# cpan |
10
|
3
|
|
|
3
|
|
20
|
use URI::Escape qw(uri_escape_utf8); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
135
|
|
11
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
12
|
3
|
|
|
|
|
26
|
new => 1, |
13
|
|
|
|
|
|
|
ro => [qw(resolver spec)], |
14
|
3
|
|
|
3
|
|
27
|
); |
|
3
|
|
|
|
|
5
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub example { |
17
|
22
|
|
|
22
|
0
|
33
|
my $self = shift; |
18
|
22
|
|
|
|
|
54
|
return $self->resolver->example(@_); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub header { |
22
|
18
|
|
|
18
|
0
|
41
|
my ($self) = @_; |
23
|
18
|
50
|
|
|
|
44
|
my $header = $self->spec->{header} or return ''; |
24
|
0
|
0
|
|
|
|
0
|
my $resource = $header->definition or return ''; |
25
|
0
|
|
|
|
|
0
|
my $example = $self->example($resource); |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
0
|
return '' unless defined $example; |
28
|
0
|
0
|
|
|
|
0
|
return '' unless (ref $example) eq 'HASH'; |
29
|
0
|
0
|
|
|
|
0
|
return '' unless scalar keys %$example; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return join "\n", map { |
32
|
0
|
|
|
|
|
0
|
sprintf '%s: %s', $_ =~ s/[_]/-/gr, $example->{$_}; |
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
} sort keys %$example; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub parameter { |
37
|
9
|
|
|
9
|
0
|
289
|
my ($self) = @_; |
38
|
9
|
100
|
|
|
|
38
|
my $parameter = $self->spec->{parameter} or return ''; |
39
|
3
|
50
|
|
|
|
23
|
my $resource = $parameter->definition or return ''; |
40
|
3
|
|
|
|
|
16
|
my $example = $self->example($resource); |
41
|
|
|
|
|
|
|
|
42
|
3
|
50
|
|
|
|
8
|
return '' unless defined $example; |
43
|
3
|
50
|
|
|
|
8
|
return '' unless (ref $example) eq 'HASH'; |
44
|
3
|
50
|
|
|
|
9
|
return '' unless scalar keys %$example; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return '?' . join '&', map { |
47
|
|
|
|
|
|
|
# TODO multiple values? |
48
|
3
|
|
|
|
|
9
|
sprintf '%s=%s', map { uri_escape_utf8 $_ } $_, $example->{$_}; |
|
3
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
62
|
|
49
|
|
|
|
|
|
|
} sort keys %$example; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub body { |
53
|
24
|
|
|
24
|
0
|
179
|
my ($self) = @_; |
54
|
24
|
100
|
|
|
|
46
|
my $body = $self->spec->{body} or return ''; |
55
|
19
|
50
|
|
|
|
124
|
my $resource = $body->definition or return ''; |
56
|
19
|
|
|
|
|
94
|
my $example = $self->example($resource); |
57
|
|
|
|
|
|
|
|
58
|
19
|
50
|
|
|
|
42
|
return '' unless defined $example; |
59
|
|
|
|
|
|
|
|
60
|
19
|
100
|
|
|
|
76
|
return ref $example ? json($example) : $example; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub header_and_body { |
64
|
18
|
|
|
18
|
0
|
636
|
my ($self) = @_; |
65
|
18
|
50
|
|
|
|
48
|
join("\n", grep { defined $_ && length $_ > 0 } $self->header, $self->body); |
|
36
|
|
|
|
|
602
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |