Service/Server.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Apps/Service/Testd.pm ↑ Summary Docs/Service/Installation.pm »
1 package XAS::Service::Server;
2  
3 our $VERSION = '0.01';
4  
5 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Socket ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use HTTP::Message::PSGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 0 ▶use XAS::Constants 'CODEREF';
Subroutine BEGIN: called CC=1 SCAR=2.6
12 use POE::Filter::HTTP::Parser;
13  
14 use XAS::Class
15 debug => 0,
16 version => $VERSION,
17 base => 'XAS::Lib::Net::Server',
18 utils => ':validation',
19 vars => {
20 PARAMS => {
21 -app => { type => CODEREF },
22 }
23 }
24 ;
25  
26 # ---------------------------------------------------------------------
27 # Public Events
28 # ---------------------------------------------------------------------
29  
30 sub process_request {
31 my $self = shift;
32 my ($request, $ctx) = validate_params(\@_, [1,1]);
33  
34 my $app = $self->app;
35 my $alias = $self->alias;
36 my $version = $request->header('X-HTTP-Verstion') || '0.9';
37 my $protocol = "HTTP/$version";
38  
39 my $env = req_to_psgi($request,
40 SERVER_NAME => $self->address,
41 SERVER_PORT => $self->port,
42 SERVER_PROTOCOL => $protocol,
43 'psgi.streaming' => Plack::Util::TRUE,
44 'psgi.nonblocking' => Plack::Util::TRUE,
45 'psgi.runonce' => Plack::Util::FALSE,
46 );
47  
48 $self->log->debug(Dumper($env));
49  
50 my $r = Plack::Util::run_app($app, $env);
51 my $response = res_from_psgi($r);
52  
53 $self->log->debug(Dumper($response));
54  
55 $self->process_response($response, $ctx);
56  
57 }
58  
59 sub process_response {
60 my $self = shift;
61 my ($output, $ctx) = validate_params(\@_, [1,1]);
62  
63 my $alias = $self->alias;
64  
65 $poe_kernel->call($alias, 'client_output', $output, $ctx);
66  
67 }
68  
69 # ---------------------------------------------------------------------
70 # Public Methods
71 # ---------------------------------------------------------------------
72  
73 # ---------------------------------------------------------------------
74 # Private Events
75 # ---------------------------------------------------------------------
76  
77 sub _client_flushed {
78 my ($self, $wheel) = @_[OBJECT, ARG0];
79  
80 my $alias = $self->alias;
81 my $host = $self->peerhost($wheel);
82 my $port = $self->peerport($wheel);
83  
84 $self->log->debug(sprintf('%s: _client_flushed() - wheel: %s, host: %s, port: %s', $alias, $wheel, $host, $port));
85 $self->log->info_msg('service_client_flushed', $alias, $host, $port, $wheel);
86  
87 delete $self->{'clients'}->{$wheel};
88  
89 }
90  
91 # ---------------------------------------------------------------------
92 # Private Methods
93 # ---------------------------------------------------------------------
94  
95 sub init {
96 my $class = shift;
97  
98 my $self = $class->SUPER::init(@_);
99  
100 $self->{'filter'} = POE::Filter::HTTP::Parser->new(type => 'server');
101  
102 return $self;
103  
104 }
105  
106 1;
107  
108 __END__
« Apps/Service/Testd.pm ↑ Summary Docs/Service/Installation.pm »