line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package APISchema::Generator::Markdown::ExampleFormatter; |
2
|
3
|
|
|
3
|
|
61
|
use 5.014; |
|
3
|
|
|
|
|
9
|
|
3
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
51
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# lib |
7
|
3
|
|
|
3
|
|
253
|
use APISchema::Generator::Markdown::Formatter qw(json); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
174
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# cpan |
10
|
3
|
|
|
3
|
|
16
|
use URI::Escape qw(uri_escape_utf8); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
135
|
|
11
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
12
|
3
|
|
|
|
|
35
|
new => 1, |
13
|
|
|
|
|
|
|
ro => [qw(resolver spec)], |
14
|
3
|
|
|
3
|
|
19
|
); |
|
3
|
|
|
|
|
5
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub example { |
17
|
17
|
|
|
17
|
0
|
32
|
my $self = shift; |
18
|
17
|
|
|
|
|
51
|
return $self->resolver->example(@_); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub header { |
22
|
18
|
|
|
18
|
0
|
4411
|
my ($self) = @_; |
23
|
18
|
50
|
|
|
|
64
|
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 "\n" . 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
|
345
|
my ($self) = @_; |
38
|
9
|
100
|
|
|
|
40
|
my $parameter = $self->spec->{parameter} or return ''; |
39
|
3
|
50
|
|
|
|
29
|
my $resource = $parameter->definition or return ''; |
40
|
3
|
|
|
|
|
18
|
my $example = $self->example($resource); |
41
|
|
|
|
|
|
|
|
42
|
3
|
50
|
|
|
|
10
|
return '' unless defined $example; |
43
|
3
|
50
|
|
|
|
10
|
return '' unless (ref $example) eq 'HASH'; |
44
|
3
|
50
|
|
|
|
21
|
return '' unless scalar keys %$example; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return '?' . join '&', map { |
47
|
|
|
|
|
|
|
# TODO multiple values? |
48
|
3
|
|
|
|
|
12
|
sprintf '%s=%s', map { uri_escape_utf8 $_ } $_, $example->{$_}; |
|
3
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
75
|
|
49
|
|
|
|
|
|
|
} sort keys %$example; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub body { |
53
|
18
|
|
|
18
|
0
|
600
|
my ($self) = @_; |
54
|
18
|
100
|
|
|
|
72
|
my $body = $self->spec->{body} or return ''; |
55
|
14
|
50
|
|
|
|
158
|
my $resource = $body->definition or return ''; |
56
|
14
|
|
|
|
|
87
|
my $example = $self->example($resource); |
57
|
|
|
|
|
|
|
|
58
|
14
|
50
|
|
|
|
44
|
return '' unless defined $example; |
59
|
|
|
|
|
|
|
|
60
|
14
|
100
|
|
|
|
83
|
return "\n" . ( ref $example ? json($example) : $example ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |