blib/lib/APISchema/Generator/Router/Simple.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 49 CC 1 SCAR 6.9
CC
1
Cov
0%
generate_router
2.0
inject_routes
2.0
BEGIN
2.0
CRAP 2.0
1 package APISchema::Generator::Router::Simple;
2 use strict;
3 use warnings;
4  
5 use Hash::Merge::Simple qw(merge);
6 use Class::Load qw(load_class);
7 use Class::Accessor::Lite (
8 new => 1,
9 ro => [qw(router_class)],
10 );
11  
12 use constant ROUTER_CLASS => 'Router::Simple';
13  
14 sub generate_router {
15 my ($self, $schema) = @_;
16  
17 my $router_class = $self->router_class // ROUTER_CLASS;
18 my $router = load_class($router_class)->new;
19  
20 $self->inject_routes($schema, $router);
21 }
22  
23 sub inject_routes {
24 my ($self, $schema, $router) = @_;
25  
26 my $router_class = ref $router;
27  
28 for my $route (@{$schema->get_routes}) {
29 my $option = $route->option // {};
30 $option = merge $option, $option->{$router_class} // {};
31 $router->connect($route->title, $route->route => $route->destination, {
32 method => $route->method,
33 map { $_ => $option->{$_} } qw(host on_match),
34 });
35 }
36  
37 $router;
38 }
39  
40 1;