SockJS/Transport/XHRSend.pm

filter: Statementstmt 100% 37 / 37 Branchbran 91.6% 11 / 12 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 90.1% 64 / 71 CC 10 SCAR 15.9
CC
10
Cov
95%
dispatch_POST
8.1
_get_content
3.0
BEGIN
1.0
CRAP 4.9
« SockJS/Transport/JSONPSend.pm ↑ Summary SockJS/Session.pm »
1 package SockJS::Transport::XHRSend;
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 base 'SockJS::Transport::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 6 my $self = shift->SUPER::new(@_);
12  
13 6 push @{$self->{allowed_methods}}, 'POST';
14  
15 6 return $self;
16 }
17  
18 6 ▶sub dispatch_POST {
Subroutine dispatch_POST: called CC=8 SCAR=20.9
Pod undocumented
19 6 my $self = shift;
20 6 my ($env, $session, $path) = @_;
21  
22 6 ▶ return [404, [], ['Not found']] unless $session->is_connected;
Branch: 1 branch
BranchTrueFalseTotal
unless $session->is_connected 1 5 6
23  
24 5 my $data = $self->_get_content($env);
25 5 ▶ return $data if $data && ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $data and ref $data eq "ARRAY" 1 4 5
Condition100%3/3
$data and ref $data eq "ARRAY"
!ll&&!rl&&r
131
MC/DC100%2/2
$data and ref $data eq "ARRAY"
$data ref $data eq "ARRAY"
Truth table100%3/3
A and B
A= $dataB= ref $data eq "ARRAY"
ABresult
0X0
100
111
26  
27 4 ▶ return $self->_return_error('Payload expected.') unless length $data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 1 3 4
28  
29 3 my $json = JSON->new->utf8->allow_nonref(0);
30  
31 3 my $message;
32 3 ▶ eval { $message = $json->decode($data) } || do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $message = $json->decode($data) } } or do { return $self->_return_error("Broken JSON encoding.") } 2 1 3
33 1 return $self->_return_error('Broken JSON encoding.');
34 };
35  
36 2 ▶ if ($message && ref $message eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($message and ref $message eq "ARRAY") 2 0 2
Condition33%1/3
$message and ref $message eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
$message and ref $message eq "ARRAY"
$message ref $message eq "ARRAY"
Truth table33%1/3
A and B
A= $messageB= ref $message eq "ARRAY"
ABresult
0X0
100
111
37 2 $session->fire_event('data', @$message);
38 }
39  
40 2 return [ 204, [ 'Content-Type' => 'text/plain; charset=UTF-8' ], [] ];
41 }
42  
43 5 ▶sub _get_content {
Subroutine _get_content: called CC=3 SCAR=11.0
44 5 my $self = shift;
45 5 my ($env) = @_;
46  
47 5 ▶ my $content_length = $env->{CONTENT_LENGTH} || 0;
Condition100%2/2
$env->{'CONTENT_LENGTH'} || 0
l!l
41
MC/DC100%1/1
$env->{'CONTENT_LENGTH'} || 0
$env->{'CONTENT_LENGTH'}
Truth table100%2/2
A
A= $env->{'CONTENT_LENGTH'}
Aresult
11
00
48 5 my $rcount = $env->{'psgi.input'}->read(my $chunk, $content_length);
49  
50 5 ▶ return $self->_return_error('System error') unless $rcount == $content_length;
Branch: 1 branch
BranchTrueFalseTotal
unless $rcount == $content_length 1 4 5
51  
52 4 return $chunk;
53 }
54  
55 1 1;
« SockJS/Transport/JSONPSend.pm ↑ Summary SockJS/Session.pm »