| 1 | # Declare our package | ||||||||||||||
| 2 | package POE::Component::Server::SimpleHTTP::Connection; | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 7 | our $VERSION = '2.22'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 7 | ▶ | use Socket qw( inet_ntoa unpack_sockaddr_in ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 7 | ▶ | use POE; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 7 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 7 | has dead => ( | |||||||||||||
| 15 | is => 'rw', | ||||||||||||||
| 16 | isa => 'Bool', | ||||||||||||||
| 17 | default => 0, | ||||||||||||||
| 18 | ); | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 7 | has ssl => ( | |||||||||||||
| 21 | is => 'rw', | ||||||||||||||
| 22 | isa => 'Bool', | ||||||||||||||
| 23 | default => 0, | ||||||||||||||
| 24 | ); | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 7 | has sslcipher => ( | |||||||||||||
| 27 | is => 'rw', | ||||||||||||||
| 28 | default => undef, | ||||||||||||||
| 29 | ); | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 7 | has remote_ip => ( | |||||||||||||
| 32 | is => 'ro', | ||||||||||||||
| 33 | ); | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 7 | has remote_port => ( | |||||||||||||
| 36 | is => 'ro', | ||||||||||||||
| 37 | ); | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 7 | has remote_addr => ( | |||||||||||||
| 40 | is => 'ro', | ||||||||||||||
| 41 | ); | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 7 | has local_ip => ( | |||||||||||||
| 44 | is => 'ro', | ||||||||||||||
| 45 | ); | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 7 | has local_port => ( | |||||||||||||
| 48 | is => 'ro', | ||||||||||||||
| 49 | ); | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 7 | has local_addr => ( | |||||||||||||
| 52 | is => 'ro', | ||||||||||||||
| 53 | ); | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 7 | has ID => ( | |||||||||||||
| 56 | is => 'rw', | ||||||||||||||
| 57 | ); | ||||||||||||||
| 58 | |||||||||||||||
| 59 | has OnClose => ( | ||||||||||||||
| 60 | is => 'ro', | ||||||||||||||
| 61 | 6 | ▶ | default => sub { { } }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 62 | 7 | ); | |||||||||||||
| 63 | |||||||||||||||
| 64 | sub BUILDARGS { | ||||||||||||||
| 65 | 6 | ▶ | my $class = shift; | ||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 6 | my $self = { }; | |||||||||||||
| 68 | |||||||||||||||
| 69 | 6 | my $socket = shift; | |||||||||||||
| 70 | |||||||||||||||
| 71 | 6 | eval { | |||||||||||||
| 72 | 6 | ( $self->{'remote_port'}, $self->{'remote_addr'} ) = | |||||||||||||
| 73 | unpack_sockaddr_in( getpeername($socket) ); | ||||||||||||||
| 74 | 6 | $self->{'remote_ip'} = inet_ntoa( $self->{'remote_addr'} ); | |||||||||||||
| 75 | |||||||||||||||
| 76 | 6 | ( $self->{'local_port'}, $self->{'local_addr'} ) = | |||||||||||||
| 77 | unpack_sockaddr_in( getsockname($socket) ); | ||||||||||||||
| 78 | 6 | $self->{'local_ip'} = inet_ntoa( $self->{'local_addr'} ); | |||||||||||||
| 79 | }; | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 6 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 82 | 0 | return undef; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 6 | return $self; | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | |||||||||||||||
| 88 | sub _on_close { | ||||||||||||||
| 89 | 0 | ▶ | my ( $self, $sessionID, $state, @args ) = @_; | ||||||||||||
|
Subroutine
_on_close: not called CC=3 SCAR=24.8
| |||||||||||||||
| 90 | 0 | ▶ | if ($state) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 0 | $self->OnClose->{$sessionID} = [ $state, @args ]; | |||||||||||||
| 92 | 0 | $poe_kernel->refcount_increment( $sessionID, __PACKAGE__ ); | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | else { | ||||||||||||||
| 95 | 0 | my $data = delete $self->OnClose->{$sessionID}; | |||||||||||||
| 96 | 0 | ▶ | $poe_kernel->refcount_decrement( $sessionID, __PACKAGE__ ) if $data; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | } | ||||||||||||||
| 98 | } | ||||||||||||||
| 99 | |||||||||||||||
| 100 | sub DEMOLISH { | ||||||||||||||
| 101 | 6 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
DEMOLISH: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||
| 102 | 6 | ▶ | while ( my ( $sessionID, $data ) = each %{ $self->OnClose || {} } ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 103 | 0 | $poe_kernel->call( $sessionID, @$data ); | |||||||||||||
| 104 | 0 | $poe_kernel->refcount_decrement( $sessionID, __PACKAGE__ ); | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | 7 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 109 | |||||||||||||||
| 110 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 111 | |||||||||||||||
| 112 | # End of module | ||||||||||||||
| 113 | 7 | 1; | |||||||||||||
| 114 | |||||||||||||||
| 115 | __END__ | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =head1 NAME | ||||||||||||||
| 118 | |||||||||||||||
| 119 | POE::Component::Server::SimpleHTTP::Connection - Stores connection information for SimpleHTTP | ||||||||||||||
| 120 | |||||||||||||||
| 121 | =head1 SYNOPSIS | ||||||||||||||
| 122 | |||||||||||||||
| 123 | use POE::Component::Server::SimpleHTTP::Connection; | ||||||||||||||
| 124 | my $connection = POE::Component::Server::SimpleHTTP::Connection->new( $socket ); | ||||||||||||||
| 125 | |||||||||||||||
| 126 | # Print some stuff | ||||||||||||||
| 127 | print $connection->remote_port; | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =head1 DESCRIPTION | ||||||||||||||
| 130 | |||||||||||||||
| 131 | This module simply holds some information from a SimpleHTTP connection. | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =head2 METHODS | ||||||||||||||
| 134 | |||||||||||||||
| 135 | my $connection = POE::Component::Server::SimpleHTTP::Connection->new( $socket ); | ||||||||||||||
| 136 | |||||||||||||||
| 137 | $connection->remote_ip(); # Returns remote ip in dotted quad format ( 1.1.1.1 ) | ||||||||||||||
| 138 | $connection->remote_port(); # Returns remote port | ||||||||||||||
| 139 | $connection->remote_addr(); # Returns true remote address, consult the L<Socket> POD | ||||||||||||||
| 140 | $connection->local_addr(); # Returns true local address, same as above | ||||||||||||||
| 141 | $connection->local_ip(); # Returns local ip in dotted quad format ( 1.1.1.1 ) | ||||||||||||||
| 142 | $connection->local_port(); # Returns local port | ||||||||||||||
| 143 | $connection->dead(); # Returns a boolean value whether the socket is closed or not | ||||||||||||||
| 144 | $connection->ssl(); # Returns a boolean value whether the socket is SSLified or not | ||||||||||||||
| 145 | $connection->sslcipher(); # Returns the SSL Cipher type or undef if not SSL | ||||||||||||||
| 146 | $connection->ID(); # unique ID of this connection | ||||||||||||||
| 147 | |||||||||||||||
| 148 | =head2 EXPORT | ||||||||||||||
| 149 | |||||||||||||||
| 150 | Nothing. | ||||||||||||||
| 151 | |||||||||||||||
| 152 | =head1 SEE ALSO | ||||||||||||||
| 153 | |||||||||||||||
| 154 | L<POE::Component::Server::SimpleHTTP>, | ||||||||||||||
| 155 | L<POE::Component::Server::SimpleHTTP::Response> | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =head1 AUTHOR | ||||||||||||||
| 158 | |||||||||||||||
| 159 | Apocalypse E<lt>apocal@cpan.orgE<gt> | ||||||||||||||
| 160 | |||||||||||||||
| 161 | Chris C<BinGOs> Williams <chris@bingosnet.co.uk> | ||||||||||||||
| 162 | |||||||||||||||
| 163 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 164 | |||||||||||||||
| 165 | Copyright E<copy> Apocalypse and Chris Williams | ||||||||||||||
| 166 | |||||||||||||||
| 167 | This library is free software; you can redistribute it and/or modify | ||||||||||||||
| 168 | it under the same terms as Perl itself. | ||||||||||||||
| 169 | |||||||||||||||
| 170 | =cut | ||||||||||||||