HTTPD/HTTPServer.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 20.0% 1 / 5 totaltotal 81.8% 63 / 77 CC 4 SCAR 3.8
CC
4
Cov
88%
__ANON__
2.3
new
2.0
__ANON__
2.0
CRAP 1.5
« HTTPD/Util.pm ↑ Summary
1 package AnyEvent::HTTPD::HTTPServer;
2 12 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Object::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use AnyEvent::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 12 ▶use AnyEvent::HTTPD::HTTPConnection;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 our @ISA = qw/Object::Event/;
11  
12 =head1 NAME
13  
14 AnyEvent::HTTPD::HTTPServer - A simple and plain http server
15  
16 =head1 DESCRIPTION
17  
18 This class handles incoming TCP connections for HTTP clients.
19 It's used by L<AnyEvent::HTTPD> to do it's job.
20  
21 It has no public interface yet.
22  
23 =head1 COPYRIGHT & LICENSE
24  
25 Copyright 2008-2011 Robin Redeker, all rights reserved.
26  
27 This program is free software; you can redistribute it and/or modify it
28 under the same terms as Perl itself.
29  
30 =cut
31  
32 11 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
33 11 my $this = shift;
34 11 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0110
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
35 11 my $self = {
36 connection_class => "AnyEvent::HTTPD::HTTPConnection",
37 allowed_methods => [ qw/GET HEAD POST/ ],
38 @_,
39 };
40 11 bless $self, $class;
41  
42 11 my $rself = $self;
43  
44 11 weaken $self;
45  
46 $self->{srv} =
47 15 ▶ tcp_server $self->{host}, $self->{port}, sub {
Subroutine __ANON__: called CC=2 SCAR=8.4
48 15 my ($fh, $host, $port) = @_;
49  
50 15 ▶ unless ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 0 15 15
51 0 $self->event (error => "couldn't accept client: $!");
52 0 return;
53 }
54  
55 15 $self->accept_connection ($fh, $host, $port);
56 11 ▶ }, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 11 my ($fh, $host, $port) = @_;
58 11 $self->{real_port} = $port;
59 11 $self->{real_host} = $host;
60 11 return $self->{backlog};
61 11 };
62  
63 11 return $self
64 }
65  
66 19 ▶sub port { $_[0]->{real_port} }
Subroutine port: called CC=1 SCAR=0.0
Pod undocumented
67  
68 0 ▶sub host { $_[0]->{real_host} }
Subroutine host: not called CC=1 SCAR=6.9
Pod undocumented
69  
70 2 ▶sub allowed_methods { $_[0]->{allowed_methods} }
Subroutine allowed_methods: called CC=1 SCAR=0.0
Pod undocumented
71  
72 15 ▶sub accept_connection {
Subroutine accept_connection: called CC=1 SCAR=0.0
Pod undocumented
73 15 my ($self, $fh, $h, $p) = @_;
74  
75 my $htc =
76 $self->{connection_class}->new (
77 fh => $fh,
78 request_timeout => $self->{request_timeout},
79 allowed_methods => $self->{allowed_methods},
80 ssl => $self->{ssl},
81 15 host => $h,
82 port => $p);
83  
84 15 $self->{handles}->{$htc} = $htc;
85  
86 15 weaken $self;
87  
88 12 ▶ $htc->reg_cb (disconnect => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
89 12 ▶ if (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self) 12 0 12
90 12 delete $self->{handles}->{$_[0]};
91 12 $self->event (disconnect => $_[0], $_[1]);
92 }
93 15 });
94  
95 15 $self->event (connect => $htc);
96 }
97  
98 12 1;
« HTTPD/Util.pm ↑ Summary