line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::App::APISchema::MockServer; |
2
|
1
|
|
|
1
|
|
2097
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use parent qw(Plack::Component); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
4026
|
use Plack::Util::Accessor qw(schema); |
|
1
|
|
|
|
|
218
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
371
|
use Plack::Request; |
|
1
|
|
|
|
|
40221
|
|
|
1
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
347
|
use APISchema::JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
209
|
use APISchema::Generator::Router::Simple; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
11
|
1
|
|
|
1
|
|
246
|
use APISchema::Generator::Markdown::ResourceResolver; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
82
|
|
12
|
1
|
|
|
1
|
|
433
|
use APISchema::Generator::Markdown::ExampleFormatter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
208
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub call { |
15
|
2
|
|
|
2
|
1
|
22328
|
my ($self, $env) = @_; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
66
|
my $req = Plack::Request->new($env); |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
36
|
my ($matched, $router_simple_route) = $self->router->routematch($env); |
20
|
|
|
|
|
|
|
|
21
|
2
|
100
|
|
|
|
73
|
unless ($matched) { |
22
|
1
|
|
|
|
|
17
|
return [404, ['Content-Type' => 'text/plain; charset=utf-8'], ['not found']]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
4
|
my $resource_root = $self->schema->get_resource_root; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
10
|
my $route = $self->schema->get_route_by_name($router_simple_route->name); |
28
|
1
|
|
|
|
|
4
|
my $response_resource = $self->schema->get_resource_by_name($route->response_resource); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
10
|
my $resolver = APISchema::Generator::Markdown::ResourceResolver->new(schema => $resource_root); |
31
|
1
|
|
|
|
|
13
|
my $example = $resolver->example($response_resource->definition); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
my $response_body; |
34
|
1
|
50
|
|
|
|
4
|
if (ref $example) { |
35
|
1
|
|
|
|
|
4
|
$response_body = encode_json_canonical($example); |
36
|
|
|
|
|
|
|
} else { |
37
|
0
|
|
|
|
|
0
|
$response_body = $example; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
18
|
return [200, ['Content-Type' => 'application/json; charset=utf-8'], [$response_body]]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub router { |
44
|
3
|
|
|
3
|
0
|
1006
|
my ($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
3
|
100
|
|
|
|
25
|
return $self->{router} if $self->{router}; |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
20
|
my $generator = APISchema::Generator::Router::Simple->new; |
49
|
2
|
|
|
|
|
22
|
$self->{router} = $generator->generate_router($self->schema); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
__END__ |