| 1 | package Kelp::Module::WebSocket::AnyEvent::Connection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Kelp::Module::WebSocket::AnyEvent::Connection::VERSION = '1.05'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Kelp::Base; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | attr "-id"; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | attr "-manager"; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | attr "-connection"; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | attr "data" => sub { {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $self = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | $self->manager->connections->{$self->id} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | weaken($self->{manager}); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | weaken($self->{connection}); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub send | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $serializer = $self->manager->get_serializer; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $is_inst = blessed $message && $message->isa("AnyEvent::WebSocket::Message"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
builtin::blessed($message) && $message->isa('AnyEvent::WebSocket::Message')
MC/DC0%0/2
builtin::blessed($message) && $message->isa('AnyEvent::WebSocket::Message')
builtin::blessed($message)
$message->isa('AnyEvent::WebSocket::Message')
Truth table0%0/3
A && B
A= builtin::blessed($message)B= $message->isa('AnyEvent::WebSocket::Message')
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($serializer && (!blessed $message || !$is_inst)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$serializer and not builtin::blessed($message) && $is_inst
builtin::blessed($message) && $is_inst
MC/DC0%0/3
$serializer and not builtin::blessed($message) && $is_inst
$serializer
builtin::blessed($message)
$is_inst
Truth table0%0/4
A and not(B && C)
A= $serializerB= builtin::blessed($message)C= $is_inst
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $message = $serializer->encode($message); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (ref $message && !$is_inst) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $message and not $is_inst
MC/DC0%0/2
ref $message and not $is_inst
ref $message
not $is_inst
Truth table0%0/3
A and not(B)
A= ref $messageB= not $is_inst
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | carp "invalid data sent to websocket peer, disconnecting"; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $self->connection->close; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $self->connection->send($message); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | sub close | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | delete $self->manager->connections->{$self->id}; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->connection->close; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||||||||||||||||