| 1 | package SocketIO::Emitter; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = 0.04; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Redis; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Data::MessagePack; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | has redis => ( is => 'rw'); | |||||||||||||||||||||||||||
| 13 | 2 | has key => ( is => 'rw'); | |||||||||||||||||||||||||||
| 14 | 2 | has prefix => ( is => 'rw'); | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | has rooms => ( is => 'rw', default => sub {[]} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | has flags => ( is => 'rw', default => sub {{}} ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | has messagepack => ( is => 'rw', default => sub { Data::MessagePack->new() } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | my $UID = 'emitter'; | |||||||||||||||||||||||||||
| 20 | 2 | my $EVENT = 2; | |||||||||||||||||||||||||||
| 21 | 2 | my $BINARY_EVENT = 5; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | # redis | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $redis = $self->redis || Redis->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->redis || 'Redis'->new
MC/DC0%0/2
$self->redis || 'Redis'->new
$self->redis
'Redis'->new
Truth table0%0/3
A || B
A= $self->redisB= 'Redis'->new
| |||||||||||||||||||||||||||||
| 27 | 0 | $self->redis($redis); | |||||||||||||||||||||||||||
| 28 | # prefix | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $self->prefix($self->key ? $self->key : 'socket.io'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub json { $_[0]->flags->{json} = 1; $_[0]; } | ||||||||||||||||||||||||||
|
Subroutine
json: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub volatile { $_[0]->flags->{volatile} = 1; $_[0]; } | ||||||||||||||||||||||||||
|
Subroutine
volatile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub broadcast { $_[0]->flags->{broadcast} = 1; $_[0]; } | ||||||||||||||||||||||||||
|
Subroutine
broadcast: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub in { | ||||||||||||||||||||||||||
|
Subroutine
in: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my ($self, $room) = @_; | |||||||||||||||||||||||||||
| 38 | 0 | push @{$self->rooms}, $room | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | unless grep { $_ eq $room } @{$self->rooms}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub to { | ||||||||||||||||||||||||||
|
Subroutine
to: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($self, $room) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | $self->in($room); | |||||||||||||||||||||||||||
| 46 | 0 | $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub of { | ||||||||||||||||||||||||||
|
Subroutine
of: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($self, $nsp) = @_; | |||||||||||||||||||||||||||
| 51 | 0 | $self->flags->{nsp} = $nsp; | |||||||||||||||||||||||||||
| 52 | 0 | $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub emit { | ||||||||||||||||||||||||||
|
Subroutine
emit: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->flags->{nsp} = '/' unless exists $self->{flags}->{nsp}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | my $chn = $self->prefix . '#' . $self->flags->{nsp} . '#'; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $pack_data = $self->pack(@args); | |||||||||||||||||||||||||||
| 62 | 0 | my $packed = $self->messagepack->utf8->pack($pack_data); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (scalar @{ $self->rooms }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | for my $room (@{ $self->rooms }) { | |||||||||||||||||||||||||||
| 66 | 0 | my $chn_room = $chn . $room . '#'; | |||||||||||||||||||||||||||
| 67 | 0 | $self->redis->publish($chn_room, $packed); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||
| 70 | 0 | $self->redis->publish($chn, $packed); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # clear | ||||||||||||||||||||||||||||
| 74 | 0 | $self->clear; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub pack { | ||||||||||||||||||||||||||
|
Subroutine
pack: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my %packet; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $packet{type} = ($self->include_binary(@args)) ? $BINARY_EVENT : $EVENT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $packet{data} = \@args; | |||||||||||||||||||||||||||
| 85 | 0 | $packet{nsp} = delete $self->flags->{'nsp'}; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | return [$UID, \%packet, { rooms => $self->rooms, flags => $self->flags }]; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | $self->rooms([]); | |||||||||||||||||||||||||||
| 94 | 0 | $self->flags({}); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub include_binary { | ||||||||||||||||||||||||||
|
Subroutine
include_binary: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | for(@args) { | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | return 1 if $_ && /[[:^ascii:]]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ and /[[:^ascii:]]/
MC/DC0%0/2
$_ and /[[:^ascii:]]/
$_
/[[:^ascii:]]/
Truth table0%0/3
A and B
A= $_B= /[[:^ascii:]]/
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||