line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package APISchema::Route; |
2
|
10
|
|
|
10
|
|
2188
|
use strict; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
320
|
|
3
|
10
|
|
|
10
|
|
49
|
use warnings; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
251
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# lib |
6
|
10
|
|
|
10
|
|
2233
|
use APISchema::Resource; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
494
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# cpan |
9
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
10
|
10
|
|
|
|
|
55
|
new => 1, |
11
|
|
|
|
|
|
|
rw => [qw(route title description destination method option |
12
|
|
|
|
|
|
|
request_resource response_resource)], |
13
|
10
|
|
|
10
|
|
75
|
); |
|
10
|
|
|
|
|
19
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _canonical_resource { |
16
|
83
|
|
|
83
|
|
217
|
my ($self, $method, $resource_root, $extra_args, $filter) = @_; |
17
|
|
|
|
|
|
|
|
18
|
83
|
|
|
|
|
155
|
$method = "${method}_resource"; |
19
|
83
|
|
|
|
|
272
|
my $resource = $self->$method(); |
20
|
83
|
|
|
|
|
482
|
for (@$extra_args) { |
21
|
28
|
100
|
100
|
|
|
151
|
last unless $resource && ref $resource eq 'HASH'; |
22
|
15
|
100
|
|
|
|
56
|
last unless $resource->{$_}; |
23
|
8
|
|
|
|
|
20
|
$resource = $resource->{$_}; |
24
|
|
|
|
|
|
|
} |
25
|
83
|
100
|
|
|
|
248
|
$resource = { body => $resource } unless ref $resource; |
26
|
|
|
|
|
|
|
|
27
|
83
|
100
|
|
|
|
221
|
$filter = [qw(header parameter body)] unless scalar @$filter; |
28
|
83
|
|
|
|
|
191
|
my %filter = map { $_ => 1 } grep { $resource->{$_} } @$filter; |
|
84
|
|
|
|
|
266
|
|
|
249
|
|
|
|
|
457
|
|
29
|
|
|
|
|
|
|
return +{ |
30
|
|
|
|
|
|
|
%$resource, |
31
|
|
|
|
|
|
|
map { |
32
|
84
|
|
|
|
|
189
|
my $name = $resource->{$_}; |
33
|
84
|
|
|
|
|
697
|
$_ => APISchema::Resource->new( |
34
|
|
|
|
|
|
|
title => $name, |
35
|
|
|
|
|
|
|
definition => ,+{ |
36
|
|
|
|
|
|
|
%$resource_root, |
37
|
|
|
|
|
|
|
'$ref' => sprintf '#/resource/%s', $name, |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
); |
40
|
83
|
|
|
|
|
318
|
} grep { $filter{$_} } qw(header parameter body), |
|
249
|
|
|
|
|
408
|
|
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub canonical_request_resource { |
45
|
41
|
|
|
41
|
0
|
123
|
my ($self, $resource_root, $extra_args, $filter) = @_; |
46
|
41
|
|
100
|
|
|
249
|
return $self->_canonical_resource( |
|
|
|
100
|
|
|
|
|
47
|
|
|
|
|
|
|
request => $resource_root, |
48
|
|
|
|
|
|
|
$extra_args // [], $filter // [], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub canonical_response_resource { |
53
|
42
|
|
|
42
|
0
|
116
|
my ($self, $resource_root, $extra_args, $filter) = @_; |
54
|
42
|
|
50
|
|
|
244
|
return $self->_canonical_resource( |
|
|
|
100
|
|
|
|
|
55
|
|
|
|
|
|
|
response => $resource_root, |
56
|
|
|
|
|
|
|
$extra_args // [], $filter // [], |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |