Handler/AnyEvent/ReverseHTTP.pm

filter: Statementstmt 35.8% 19 / 53 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 3 totaltotal 32.4% 25 / 77 CC 5 SCAR 18.5
CC
5
Cov
31%
__ANON__
20.0
__ANON__
6.0
new
2.0
CRAP 6.4
↑ Summary Server/ReverseHTTP.pm »
1 package Plack::Handler::AnyEvent::ReverseHTTP;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = '0.04';
5  
6 1 ▶use AnyEvent::ReverseHTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::Message::PSGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12 0 my($class, %args) = @_;
13 0 bless \%args, $class;
14 }
15  
16 0 ▶sub register_service {
Subroutine register_service: not called CC=1 SCAR=6.9
Pod undocumented
17 0 my($self, $app) = @_;
18 0 ▶ $self->{guard} = reverse_http $self->{host}, $self->{token}, sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
19 0 my $req = shift;
20 0 my $env = $req->to_psgi;
21  
22 0 ▶ if (my $client = delete $env->{HTTP_REQUESTING_CLIENT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = delete $env->{"HTTP_REQUESTING_CLIENT"}) 0 0 0
23 0 @{$env}{qw( REMOTE_ADDR REMOTE_PORT )} = split /:/, $client, 2;
24 }
25  
26 0 $env->{'psgi.nonblocking'} = Plack::Util::TRUE;
27 0 $env->{'psgi.streaming'} = Plack::Util::TRUE;
28 0 $env->{'psgi.multithread'} = Plack::Util::FALSE;
29 0 $env->{'psgi.multiprocess'} = Plack::Util::FALSE;
30 0 $env->{'psgi.run_once'} = Plack::Util::FALSE;
31  
32 0 my $r = $app->($env);
33 0 ▶ if (ref $r eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r eq 'ARRAY') { } 0 0 0
elsif (ref $r eq 'CODE') { } 0 0 0
34 0 return HTTP::Response->from_psgi($r);
35 } elsif (ref $r eq 'CODE') {
36 0 my $cv = AE::cv;
37 0 ▶ $r->(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
38 0 my $r = shift;
39  
40 0 ▶ if (defined $r->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $r->[2]) { } 0 0 0
41 0 my $res = HTTP::Response->from_psgi($r);
42 0 $cv->send($res);
43 } else {
44 0 my $res = HTTP::Response->from_psgi([ $r->[0], $r->[1], [] ]); # dummy
45 0 my @body;
46 return Plack::Util::inline_object
47 0 ▶ write => sub { push @body, $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ close => sub { $res->content(join '', @body); $cv->send($res) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 }
50 0 });
51 0 return $cv;
52 } else {
53 0 die "Bad response: $r";
54 }
55 0 };
56 }
57  
58 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my $self = shift;
60 0 $self->register_service(@_);
61 0 AE::cv->recv;
62 }
63  
64 1 1;
65  
66 __END__
↑ Summary Server/ReverseHTTP.pm »