File Coverage

blib/lib/XAS/Service/Server.pm
Criterion Covered Total %
statement 27 54 50.0
branch n/a
condition 0 2 0.0
subroutine 9 13 69.2
pod 3 3 100.0
total 39 72 54.1


line stmt bran cond sub pod time code
1             package XAS::Service::Server;
2              
3             our $VERSION = '0.01';
4              
5 1     1   13460 use POE;
  1         30146  
  1         5  
6 1     1   41743 use Try::Tiny;
  1         1627  
  1         44  
7 1     1   438 use Plack::Util;
  1         4159  
  1         20  
8 1     1   530 use Data::Dumper;
  1         4665  
  1         48  
9 1     1   5 use Socket ':all';
  1         1  
  1         908  
10 1     1   439 use HTTP::Message::PSGI;
  1         5263  
  1         44  
11 1     1   525 use XAS::Constants 'CODEREF';
  1         21102  
  1         6  
12 1     1   706 use POE::Filter::HTTP::Parser;
  1         25772  
  1         47  
13              
14             use XAS::Class
15 1         9 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 1     1   423 ;
  1         388  
25              
26             # ---------------------------------------------------------------------
27             # Public Events
28             # ---------------------------------------------------------------------
29              
30             sub process_request {
31 0     0 1   my $self = shift;
32 0           my ($request, $ctx) = validate_params(\@_, [1,1]);
33              
34 0           my $app = $self->app;
35 0           my $alias = $self->alias;
36 0   0       my $version = $request->header('X-HTTP-Verstion') || '0.9';
37 0           my $protocol = "HTTP/$version";
38              
39 0           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 0           $self->log->debug(Dumper($env));
49              
50 0           my $r = Plack::Util::run_app($app, $env);
51 0           my $response = res_from_psgi($r);
52              
53 0           $self->log->debug(Dumper($response));
54              
55 0           $self->process_response($response, $ctx);
56              
57             }
58              
59             sub process_response {
60 0     0 1   my $self = shift;
61 0           my ($output, $ctx) = validate_params(\@_, [1,1]);
62              
63 0           my $alias = $self->alias;
64              
65 0           $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 0     0     my ($self, $wheel) = @_[OBJECT, ARG0];
79              
80 0           my $alias = $self->alias;
81 0           my $host = $self->peerhost($wheel);
82 0           my $port = $self->peerport($wheel);
83              
84 0           $self->log->debug(sprintf('%s: _client_flushed() - wheel: %s, host: %s, port: %s', $alias, $wheel, $host, $port));
85 0           $self->log->info_msg('service_client_flushed', $alias, $host, $port, $wheel);
86              
87 0           delete $self->{'clients'}->{$wheel};
88              
89             }
90              
91             # ---------------------------------------------------------------------
92             # Private Methods
93             # ---------------------------------------------------------------------
94              
95             sub init {
96 0     0 1   my $class = shift;
97              
98 0           my $self = $class->SUPER::init(@_);
99              
100 0           $self->{'filter'} = POE::Filter::HTTP::Parser->new(type => 'server');
101              
102 0           return $self;
103              
104             }
105              
106             1;
107              
108             __END__