line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::App::APISchema::MockServer; |
2
|
1
|
|
|
1
|
|
2610
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
4
|
use parent qw(Plack::Component); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
4030
|
use Plack::Util::Accessor qw(schema); |
|
1
|
|
|
|
|
215
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
453
|
use Plack::Request; |
|
1
|
|
|
|
|
37520
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
7
|
use Encode qw(encode_utf8); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
316
|
use APISchema::JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
291
|
use APISchema::Generator::Router::Simple; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
12
|
1
|
|
|
1
|
|
304
|
use APISchema::Generator::Markdown::ResourceResolver; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
13
|
1
|
|
|
1
|
|
302
|
use APISchema::Generator::Markdown::ExampleFormatter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub call { |
16
|
7
|
|
|
7
|
1
|
23721
|
my ($self, $env) = @_; |
17
|
|
|
|
|
|
|
|
18
|
7
|
|
|
|
|
34
|
my $req = Plack::Request->new($env); |
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
|
|
62
|
my ($matched, $router_simple_route) = $self->router->routematch($env); |
21
|
|
|
|
|
|
|
|
22
|
7
|
100
|
|
|
|
297
|
unless ($matched) { |
23
|
1
|
|
|
|
|
8
|
return [404, ['Content-Type' => 'text/plain; charset=utf-8'], ['not found']]; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
12
|
my $root = $self->schema->get_resource_root; |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
38
|
my $route = $self->schema->get_route_by_name($router_simple_route->name); |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
23
|
my $default_code = $route->default_responsible_code; |
31
|
6
|
|
|
|
|
14
|
my $response_resource = $route->canonical_response_resource($root, [ |
32
|
|
|
|
|
|
|
$default_code |
33
|
|
|
|
|
|
|
]); |
34
|
|
|
|
|
|
|
|
35
|
6
|
|
|
|
|
70
|
my $resolver = APISchema::Generator::Markdown::ResourceResolver->new(schema => $root); |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
52
|
my $formatter = APISchema::Generator::Markdown::ExampleFormatter->new( |
38
|
|
|
|
|
|
|
resolver => $resolver, |
39
|
|
|
|
|
|
|
spec => $response_resource, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# TODO: serve all headers defined in example |
43
|
|
|
|
|
|
|
# TODO: format body with encoding |
44
|
6
|
|
|
|
|
34
|
return [$default_code, ['Content-Type' => 'application/json; charset=utf-8'], [encode_utf8($formatter->body)]]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub router { |
48
|
8
|
|
|
8
|
0
|
969
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
8
|
100
|
|
|
|
25
|
return $self->{router} if $self->{router}; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
32
|
my $generator = APISchema::Generator::Router::Simple->new; |
53
|
7
|
|
|
|
|
45
|
$self->{router} = $generator->generate_router($self->schema); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
__END__ |