| 1 | # Declare our package | ||||||||||||||||||||
| 2 | package POE::Component::Server::SimpleHTTP::Connection; | ||||||||||||||||||||
| 3 | 9 | $POE::Component::Server::SimpleHTTP::Connection::VERSION = '2.30'; | |||||||||||||||||||
| 4 | #ABSTRACT: Stores connection information for SimpleHTTP | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 9 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 9 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 9 | ▶ | use Socket (qw( AF_INET AF_INET6 AF_UNIX inet_ntop sockaddr_family | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 9 | unpack_sockaddr_in unpack_sockaddr_in6 unpack_sockaddr_un )); | |||||||||||||||||||
| 11 | 9 | ▶ | use POE; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 9 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 9 | has dead => ( | |||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||
| 17 | isa => 'Bool', | ||||||||||||||||||||
| 18 | default => 0, | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 9 | has ssl => ( | |||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||
| 23 | isa => 'Bool', | ||||||||||||||||||||
| 24 | default => 0, | ||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 9 | has sslcipher => ( | |||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||
| 29 | default => undef, | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 9 | has remote_ip => ( | |||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 9 | has remote_port => ( | |||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 9 | has remote_addr => ( | |||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 9 | has local_ip => ( | |||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 9 | has local_port => ( | |||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 9 | has local_addr => ( | |||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 9 | has ID => ( | |||||||||||||||||||
| 57 | is => 'rw', | ||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | has OnClose => ( | ||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||
| 62 | 10 | ▶ | default => sub { { } }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 63 | 9 | ); | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 10 | ▶ | sub BUILDARGS { | ||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 66 | 10 | my $class = shift; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 10 | my $self = { }; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 10 | my $socket = shift; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 10 | eval { | |||||||||||||||||||
| 73 | 10 | my $family; | |||||||||||||||||||
| 74 | ( $family, $self->{'remote_port'}, $self->{'remote_addr'}, | ||||||||||||||||||||
| 75 | 10 | $self->{'remote_ip'} | |||||||||||||||||||
| 76 | ) = $class->get_sockaddr_info( getpeername($socket) ); | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | ( $family, $self->{'local_port'}, $self->{'local_addr'}, | ||||||||||||||||||||
| 79 | 10 | $self->{'local_ip'} | |||||||||||||||||||
| 80 | ) = $class->get_sockaddr_info( getsockname($socket) ); | ||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 10 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | return undef; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 10 | return $self; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 2 | ▶ | sub _on_close { | ||||||||||||||||||
|
Subroutine
_on_close: called CC=3 SCAR=14.2
| |||||||||||||||||||||
| 91 | 2 | my ( $self, $sessionID, $state, @args ) = @_; | |||||||||||||||||||
| 92 | 2 | ▶ | if ($state) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 2 | $self->OnClose->{$sessionID} = [ $state, @args ]; | |||||||||||||||||||
| 94 | 2 | $poe_kernel->refcount_increment( $sessionID, __PACKAGE__ ); | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||
| 97 | 0 | my $data = delete $self->OnClose->{$sessionID}; | |||||||||||||||||||
| 98 | 0 | ▶ | $poe_kernel->refcount_decrement( $sessionID, __PACKAGE__ ) if $data; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 10 | ▶ | sub DEMOLISH { | ||||||||||||||||||
|
Subroutine
DEMOLISH: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 103 | 10 | my ($self) = @_; | |||||||||||||||||||
| 104 | 10 | ▶ | while ( my ( $sessionID, $data ) = each %{ $self->OnClose || {} } ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->OnClose || {}
MC/DC0%0/1
$self->OnClose || {}
$self->OnClose
Truth table50%1/2
A
A= $self->OnClose
| |||||||||||||||||||||
| 105 | 2 | $poe_kernel->call( $sessionID, @$data ); | |||||||||||||||||||
| 106 | 2 | $poe_kernel->refcount_decrement( $sessionID, __PACKAGE__ ); | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 37 | ▶ | sub get_sockaddr_info { | ||||||||||||||||||
|
Subroutine
get_sockaddr_info: called CC=5 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||
| 111 | 37 | my $class = shift; | |||||||||||||||||||
| 112 | 37 | my $sockaddr = shift; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 37 | my $family = sockaddr_family( $sockaddr ); | |||||||||||||||||||
| 115 | 37 | my ( $port, $address, $straddress ); | |||||||||||||||||||
| 116 | 37 | ▶ | if ( $family == AF_INET ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 117 | 33 | ( $port, $address ) = unpack_sockaddr_in( $sockaddr ); | |||||||||||||||||||
| 118 | 33 | $straddress = inet_ntop( $family, $address ); | |||||||||||||||||||
| 119 | } elsif ( $family == AF_INET6 ) { | ||||||||||||||||||||
| 120 | 4 | ( $port, $address ) = unpack_sockaddr_in6( $sockaddr ); | |||||||||||||||||||
| 121 | 4 | $straddress = inet_ntop( $family, $address ); | |||||||||||||||||||
| 122 | } elsif ( $family == AF_UNIX ) { | ||||||||||||||||||||
| 123 | 0 | $address = unpack_sockaddr_un( $sockaddr ); | |||||||||||||||||||
| 124 | 0 | ▶ | $straddress = $address // '<local>'; | ||||||||||||||||||
|
Condition0%0/2
$address // "<local>"
MC/DC0%0/1
$address // "<local>"
$address
Truth table0%0/2
A
A= $address
| |||||||||||||||||||||
| 125 | 0 | $port = undef; | |||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||
| 127 | 0 | $address = $port = undef; | |||||||||||||||||||
| 128 | 0 | $straddress = '<unknown>'; | |||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | 37 | return ( $family, $address, $port, $straddress ); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 9 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | # End of module | ||||||||||||||||||||
| 138 | 9 | 1; | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||