SockJS/Session.pm

filter: Statementstmt 62.2% 33 / 53 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 8 totaltotal 53.0% 43 / 81 CC 6 SCAR 14.6
CC
6
Cov
57%
fire_event
12.0
write
6.0
type
2.0
CRAP 4.3
« SockJS/Transport/XHRSend.pm ↑ Summary SockJS/Connection.pm »
1 package SockJS::Session;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 2 my $class = shift;
11 2 my (%params) = @_;
12  
13 2 my $self = {};
14 2 bless $self, $class;
15  
16 2 $self->{id} = $params{id};
17 2 $self->{type} = $params{type};
18 2 $self->{conn} = $params{connection};
19  
20 2 return $self;
21 }
22  
23 1 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
Pod undocumented
24 1 my $self = shift;
25 1 my ($key, $value) = @_;
26  
27 1 $self->{custom}->{$key} = $value;
28  
29 1 return $self;
30 }
31  
32 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
33 1 my $self = shift;
34 1 my ($key) = @_;
35  
36 1 return $self->{custom}->{$key};
37 }
38  
39 0 ▶sub type { $_[0]->{type} }
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 0 ▶sub on {
Subroutine on: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my $self = shift;
43 0 my ($event, $cb) = @_;
44  
45 0 push @{$self->{"on_$event"}}, $cb;
46  
47 0 return $self;
48 }
49  
50 1 ▶sub write {
Subroutine write: called CC=4 SCAR=17.9
Pod undocumented
51 1 my $self = shift;
52  
53 1 my $message;
54 1 ▶ if (ref $_[0] eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'SCALAR') { } 0 1 1
55 0 $message = ${$_[0]};
56 0 ▶ $message = Encode::encode('UTF-8', $message) if Encode::is_utf8($message);
Branch: 1 branch
BranchTrueFalseTotal
if &Encode::is_utf8($message) 0 0 0
57 }
58 else {
59 1 ▶ $message = 'a' . JSON->new->ascii(1)->encode([@_]) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
60 }
61  
62 1 return $self->{conn}->write($message);
63 }
64  
65 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my $self = shift;
67 0 my ($code, $message) = @_;
68  
69 0 $self->{conn}->close($code, $message);
70  
71 0 return $self;
72 }
73  
74 0 ▶sub fire_event {
Subroutine fire_event: not called CC=3 SCAR=24.8
Pod undocumented
75 0 my $self = shift;
76 0 my $event = shift;
77  
78 0 ▶ if (exists $self->{"on_$event"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$self{"on_$event"}) 0 0 0
79 0 foreach my $ev (@{$self->{"on_$event"}}) {
80 0 $ev->($self, @_);
81 }
82 }
83  
84 0 return $self;
85 }
86  
87 1 1;
« SockJS/Transport/XHRSend.pm ↑ Summary SockJS/Connection.pm »