Clio/Server/HTTP.pm

filter: Statementstmt 42.8% 24 / 56 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod 100% 3 / 3 totaltotal 43.5% 34 / 78 CC 5 SCAR 19.3
CC
5
Cov
38%
__ANON__
20.0
build_app
6.0
start
2.0
CRAP 6.9
« Clio.pm ↑ Summary Clio/Server/HTTP/Client/WebSocket.pm »
1  
2 package Clio::Server::HTTP;
3 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $Clio::Server::HTTP::AUTHORITY = 'cpan:AJGB';
5 }
6 {
7 1 $Clio::Server::HTTP::VERSION = '0.02';
8 }
9 # ABSTRACT: Clio HTTP Server
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Twiggy::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 extends qw( Clio::Server );
20  
21 1 with 'Clio::Role::UUIDMaker';
22  
23  
24 0 ▶sub start {
Subroutine start: not called CC=1 SCAR=6.9
Pod documented
25 0 my $self = shift;
26  
27 0 my $listen = $self->c->config->server_host_port;
28  
29 my $twiggy = Twiggy::Server->new(
30 0 %{ $listen }
31 );
32  
33 0 $self->c->log->info(
34 "Started ", __PACKAGE__, " on $listen->{host}:$listen->{port}"
35 );
36 0 $twiggy->run( $self->build_app );
37 }
38  
39  
40 0 ▶sub build_app {
Subroutine build_app: not called CC=2 SCAR=17.9
Pod documented
41 0 my $self = shift;
42  
43 0 my $config = $self->c->config->ServerConfig;
44  
45 0 my $app = $self->to_app;
46 0 ▶ if ( my $builder = $config->{Builder} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $builder = $config->{"Builder"}) 0 0 0
47 0 my $wrapper = Plack::Util::load_psgi($builder);
48  
49 0 $app = $wrapper->($app);
50 }
51  
52 0 $DB::single=1;
53 0 return $app;
54 }
55  
56  
57 0 ▶sub to_app {
Subroutine to_app: not called CC=1 SCAR=6.9
Pod documented
58 0 my $self = shift;
59  
60 0 my $log = $self->c->log;
61  
62 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
63 0 my ($env) = @_;
64  
65 0 my $req = Plack::Request->new( $env );
66  
67 0 my %proc_manager_args;
68 my $post_data;
69 0 ▶ if ( $req->method eq 'POST' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->method eq "POST") 0 0 0
70 0 $post_data = $req->body_parameters;
71 $proc_manager_args{client_id} = $post_data->{'metadata.id'}
72 0 ▶ if exists $post_data->{'metadata.id'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $post_data->{"metadata.id"} 0 0 0
73 }
74  
75 0 my $process = $self->c->process_manager->get_first_available(
76 %proc_manager_args
77 );
78 0 ▶ if ( $process ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process) 0 0 0
79 0 $log->debug("got process: ". $process->id );
80  
81 0 my $uuid = $self->create_uuid;
82  
83 0 $log->debug("new client(". $req->address .") id: $uuid");
84  
85 0 my $client = $self->clients_manager->new_client(
86 id => $uuid,
87 req => $req,
88 );
89  
90 0 $client->attach_to_process( $process );
91  
92 0 return $client->respond(
93 input => $post_data
94 );
95 }
96  
97 0 return [ 503, [
98 'Content-Type' => 'text/plain; charset=utf-8',
99 'Access-Control-Allow-Origin' => '*',
100 ], [ "No engines available" ] ];
101 }
102 0 }
103  
104  
105 1 1;
106  
107  
108  
109  
110 __END__
« Clio.pm ↑ Summary Clio/Server/HTTP/Client/WebSocket.pm »