line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package APISchema::Generator::Router::Simple; |
2
|
4
|
|
|
4
|
|
2416
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
109
|
|
3
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
105
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
1239
|
use Hash::Merge::Simple qw(merge); |
|
4
|
|
|
|
|
1613
|
|
|
4
|
|
|
|
|
227
|
|
6
|
4
|
|
|
4
|
|
1025
|
use Class::Load qw(load_class); |
|
4
|
|
|
|
|
46968
|
|
|
4
|
|
|
|
|
309
|
|
7
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
8
|
4
|
|
|
|
|
34
|
new => 1, |
9
|
|
|
|
|
|
|
ro => [qw(router_class)], |
10
|
4
|
|
|
4
|
|
32
|
); |
|
4
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
395
|
use constant ROUTER_CLASS => 'Router::Simple'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
877
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub generate_router { |
15
|
12
|
|
|
12
|
0
|
110
|
my ($self, $schema) = @_; |
16
|
|
|
|
|
|
|
|
17
|
12
|
|
100
|
|
|
54
|
my $router_class = $self->router_class // ROUTER_CLASS; |
18
|
12
|
|
|
|
|
191
|
my $router = load_class($router_class)->new; |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
10920
|
$self->inject_routes($schema, $router); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub inject_routes { |
24
|
13
|
|
|
13
|
0
|
147
|
my ($self, $schema, $router) = @_; |
25
|
|
|
|
|
|
|
|
26
|
13
|
|
|
|
|
31
|
my $router_class = ref $router; |
27
|
|
|
|
|
|
|
|
28
|
13
|
|
|
|
|
23
|
for my $route (@{$schema->get_routes}) { |
|
13
|
|
|
|
|
53
|
|
29
|
16
|
|
100
|
|
|
542
|
my $option = $route->option // {}; |
30
|
16
|
|
50
|
|
|
171
|
$option = merge $option, $option->{$router_class} // {}; |
31
|
|
|
|
|
|
|
$router->connect($route->title, $route->route => $route->destination, { |
32
|
|
|
|
|
|
|
method => $route->method, |
33
|
16
|
|
|
|
|
266
|
map { $_ => $option->{$_} } qw(host on_match), |
|
32
|
|
|
|
|
262
|
|
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
13
|
|
|
|
|
850
|
$router; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |