line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::JsonAPI::Autodoc; |
2
|
14
|
|
|
14
|
|
877871
|
use 5.008005; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
436
|
|
3
|
14
|
|
|
14
|
|
55
|
use strict; |
|
14
|
|
|
|
|
17
|
|
|
14
|
|
|
|
|
387
|
|
4
|
14
|
|
|
14
|
|
47
|
use warnings; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
414
|
|
5
|
14
|
|
|
14
|
|
5108
|
use parent qw/Exporter/; |
|
14
|
|
|
|
|
2786
|
|
|
14
|
|
|
|
|
65
|
|
6
|
14
|
|
|
14
|
|
610
|
use Carp; |
|
14
|
|
|
|
|
18
|
|
|
14
|
|
|
|
|
853
|
|
7
|
14
|
|
|
14
|
|
58
|
use Test::More (); |
|
14
|
|
|
|
|
20
|
|
|
14
|
|
|
|
|
161
|
|
8
|
14
|
|
|
14
|
|
5712
|
use Scope::Guard; |
|
14
|
|
|
|
|
4302
|
|
|
14
|
|
|
|
|
511
|
|
9
|
14
|
|
|
14
|
|
2508
|
use LWP::UserAgent; |
|
14
|
|
|
|
|
96172
|
|
|
14
|
|
|
|
|
373
|
|
10
|
14
|
|
|
14
|
|
4738
|
use Test::JsonAPI::Autodoc::Markdown; |
|
14
|
|
|
|
|
34
|
|
|
14
|
|
|
|
|
389
|
|
11
|
14
|
|
|
14
|
|
5112
|
use Test::JsonAPI::Autodoc::Request; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
435
|
|
12
|
14
|
|
|
14
|
|
5106
|
use Test::JsonAPI::Autodoc::Response; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
815
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw/ |
15
|
|
|
|
|
|
|
describe |
16
|
|
|
|
|
|
|
http_ok |
17
|
|
|
|
|
|
|
plack_ok |
18
|
|
|
|
|
|
|
set_documents_path |
19
|
|
|
|
|
|
|
set_template |
20
|
|
|
|
|
|
|
/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = "0.21"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $in_describe; |
25
|
|
|
|
|
|
|
my $results; |
26
|
|
|
|
|
|
|
my $first_time; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $output_path; |
29
|
|
|
|
|
|
|
my $template; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
BEGIN { |
32
|
14
|
|
|
14
|
|
6114
|
$first_time = 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub set_documents_path { |
36
|
12
|
|
|
12
|
1
|
151934
|
$output_path = shift; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub set_template { |
40
|
1
|
|
|
1
|
1
|
5
|
$template = shift; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub describe { |
44
|
16
|
50
|
|
16
|
1
|
22882
|
if ($in_describe) { |
45
|
0
|
|
|
|
|
0
|
croak '`describe` must not call as nesting'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $guard = sub { |
49
|
|
|
|
|
|
|
return Scope::Guard->new(sub { |
50
|
16
|
|
|
|
|
186
|
undef $in_describe; |
51
|
16
|
|
|
|
|
22
|
undef $results; |
52
|
16
|
|
|
|
|
192
|
undef $first_time; |
53
|
16
|
|
|
16
|
|
143
|
}); |
54
|
16
|
|
|
|
|
94
|
}->(); |
55
|
|
|
|
|
|
|
|
56
|
16
|
|
|
|
|
198
|
$in_describe = 1; |
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
|
|
29
|
my ($description, $coderef) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# change location of test failure to be included Test::More's output |
61
|
|
|
|
|
|
|
# to be more helpful to user. |
62
|
16
|
|
|
|
|
33
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
63
|
|
|
|
|
|
|
|
64
|
16
|
|
|
|
|
69
|
my $result = Test::More::subtest($description => $coderef); |
65
|
|
|
|
|
|
|
|
66
|
16
|
100
|
66
|
|
|
12628
|
if ($result && $results && $ENV{TEST_JSONAPI_AUTODOC}) { |
|
|
|
100
|
|
|
|
|
67
|
14
|
|
|
|
|
138
|
my $markdown = Test::JsonAPI::Autodoc::Markdown->new($output_path, $template); |
68
|
14
|
|
|
|
|
59
|
$markdown->generate($description, $results, $first_time); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub http_ok { |
73
|
12
|
|
|
12
|
1
|
59607
|
my ($req, $expected_code, $note) = @_; |
74
|
12
|
|
|
|
|
46
|
return _api_ok($req, $expected_code, $note); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub plack_ok { |
78
|
4
|
|
|
4
|
1
|
9199
|
my ($plack_app, $req, $expected_code, $note) = @_; |
79
|
4
|
|
|
|
|
11
|
return _api_ok($req, $expected_code, $note, $plack_app); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _api_ok { |
83
|
16
|
|
|
16
|
|
29
|
my ($req, $expected_code, $note, $plack_app) = @_; |
84
|
|
|
|
|
|
|
|
85
|
16
|
|
|
|
|
26
|
my $description = $note; |
86
|
16
|
|
|
|
|
29
|
my $param_description = {}; |
87
|
16
|
100
|
|
|
|
59
|
if (ref $note eq 'HASH') { |
88
|
1
|
|
|
|
|
2
|
$description = $note->{description}; |
89
|
1
|
|
|
|
|
2
|
$param_description = $note->{param_description}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
16
|
|
|
|
|
24
|
my $res; |
93
|
16
|
|
|
|
|
21
|
my $is_plack_app = 0; |
94
|
16
|
100
|
|
|
|
44
|
if ($plack_app) { # for Plack::Test |
95
|
4
|
100
|
|
|
|
20
|
$res = ref $plack_app eq 'CODE' ? $plack_app->($req) # use `test_psgi` |
96
|
|
|
|
|
|
|
: $plack_app->request($req); # not use `test_psgi` |
97
|
4
|
|
|
|
|
9821
|
$is_plack_app = 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
12
|
|
|
|
|
101
|
$res = LWP::UserAgent->new->request($req); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# change location of test failure to be included Test::More's output |
104
|
|
|
|
|
|
|
# to be more helpful to user. |
105
|
16
|
|
|
|
|
25738
|
local $Test::Builder::Level = $Test::Builder::Level + 2; |
106
|
|
|
|
|
|
|
|
107
|
16
|
|
|
|
|
118
|
my $result = Test::More::is $res->code, $expected_code; |
108
|
16
|
50
|
|
|
|
7268
|
return unless $result; |
109
|
16
|
100
|
|
|
|
76
|
return unless $in_describe; |
110
|
|
|
|
|
|
|
|
111
|
15
|
|
|
|
|
137
|
my $parsed_request = Test::JsonAPI::Autodoc::Request->new->parse($req, $param_description); |
112
|
15
|
|
|
|
|
681
|
my $parsed_response = Test::JsonAPI::Autodoc::Response->new->parse($res); |
113
|
|
|
|
|
|
|
|
114
|
15
|
|
|
|
|
125
|
my $response_body = $parsed_response->{body}; |
115
|
15
|
|
|
|
|
146
|
my $response_content_type = $parsed_response->{content_type}; |
116
|
|
|
|
|
|
|
|
117
|
15
|
|
|
|
|
184
|
push @$results, { |
118
|
|
|
|
|
|
|
note => $description, |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
path => $parsed_request->{path}, |
121
|
|
|
|
|
|
|
server => $parsed_request->{server}, |
122
|
|
|
|
|
|
|
method => $parsed_request->{method}, |
123
|
|
|
|
|
|
|
query => $parsed_request->{query}, |
124
|
|
|
|
|
|
|
request_content_type => $parsed_request->{content_type}, |
125
|
|
|
|
|
|
|
request_parameters => $parsed_request->{parameters}, |
126
|
|
|
|
|
|
|
is_plack_app => $is_plack_app, |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
status => $expected_code, |
129
|
|
|
|
|
|
|
response_body => $response_body, |
130
|
|
|
|
|
|
|
response_content_type => $response_content_type, |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return +{ |
134
|
15
|
|
|
|
|
192
|
status => $expected_code, |
135
|
|
|
|
|
|
|
body => $response_body, |
136
|
|
|
|
|
|
|
content_type => $response_content_type, |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
__END__ |