WebAPI.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 41 CC 3 SCAR 18.4
CC
3
Cov
0%
register
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 package Mojolicious::Plugin::WebAPI;
2  
3 # ABSTRACT: Mojolicious::Plugin::WebAPI - mount WebAPI::DBIC in your Mojolicious app
4  
5 use Mojo::Base 'Mojolicious::Plugin';
6  
7 use WebAPI::DBIC::WebApp;
8 use WebAPI::DBIC::RouteMaker;
9 use Mojolicious::Plugin::WebAPI::Proxy;
10
11 our $VERSION = '0.04';
12
13 sub register {
14 my ($self, $app, $conf) = @_;
15  
16 my $schema = delete $conf->{schema};
17 my $route = delete $conf->{route};
18 my $debug = delete $conf->{debug};
19  
20 if ( $debug ) {
21 $ENV{WEBAPI_DBIC_DEBUG} = 1;
22 $app->log->debug( "Base route: " . $route->to_string );
23 }
24  
25 my %opts;
26 if ( $conf->{resource_opts} ) {
27 $opts{route_maker} = WebAPI::DBIC::RouteMaker->new(
28 %{ $conf->{resource_opts} },
29 );
30 }
31  
32 my $psgi_app = WebAPI::DBIC::WebApp->new({
33 %opts,
34 routes => [ map { $schema->source($_) } $schema->sources ],
35 })->to_psgi_app;
36  
37 $route->detour(
38 app => Mojolicious::Plugin::WebAPI::Proxy->new(
39 app => $psgi_app,
40 base => $route->to_string,
41 ),
42 );
43 }
44  
45 1;
46  
47 __END__