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

filter: Statementstmt 0.0% 0 / 29 Branchbran n/a Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
generate_router
2.0
BEGIN
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 for my $route (@{$schema->get_routes}) {
21 my $option = $route->option // {};
22 $option = merge $option, $option->{$router_class} // {};
23 $router->connect($route->title, $route->route => $route->destination, {
24 method => $route->method,
25 map { $_ => $option->{$_} } qw(host on_match),
26 });
27 }
28 $router;
29 }
30  
31 1;