SockJS/Transport/JSONPPolling.pm

filter: Statementstmt 96.0% 48 / 50 Branchbran 83.3% 10 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 89.6% 69 / 77 CC 8 SCAR 10.6
CC
8
Cov
92%
__ANON__
5.0
dispatch_GET
3.0
__ANON__
2.0
CRAP 2.9
« SockJS/Transport/EventSource.pm ↑ Summary SockJS/Exception.pm »
1 package SockJS::Transport::JSONPPolling;
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 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 6 my $self = shift->SUPER::new(@_);
10  
11 6 push @{$self->{allowed_methods}}, 'GET';
12  
13 6 return $self;
14 }
15  
16 6 ▶sub dispatch_GET {
Subroutine dispatch_GET: called CC=3 SCAR=11.0
Pod undocumented
17 6 my $self = shift;
18 6 my ($env, $conn, $path) = @_;
19  
20 6 my ($callback) = $env->{QUERY_STRING} =~ m/(?:^|&|;)c=([^&;]+)/;
21 6 ▶ if (!$callback) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($callback) 1 5 6
22 1 return [500, [], ['"callback" parameter required']];
23 }
24  
25 0 $callback =~ s/%(..)/chr(hex($1))/eg;
26 5 ▶ if ($callback !~ m/^[a-zA-Z0-9-_\.]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($callback =~ /^[a-zA-Z0-9-_\.]+$/) 1 4 5
27 1 return [500, [], ['invalid "callback" parameter']];
28 }
29  
30 4 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
31 4 my $respond = shift;
32  
33 4 my $writer = $respond->(
34 [ 200,
35 [ 'Content-Type' => 'application/javascript; charset=UTF-8',
36 'Connection' => 'close',
37 ]
38 ]
39 );
40  
41 4 ▶ if ($conn->is_connected && !$conn->is_reconnecting) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->is_connected and not $conn->is_reconnecting) 1 3 4
Condition66%2/3
$conn->is_connected and not $conn->is_reconnecting
!ll&&!rl&&r
301
MC/DC50%1/2
$conn->is_connected and not $conn->is_reconnecting
$conn->is_connected not $conn->is_reconnecting
Truth table66%2/3
A and not(B)
A= $conn->is_connectedB= not $conn->is_reconnecting
ABresult
0X0
100
111
42 1 my $message = $self->_wrap_message($callback,
43 'c[2010,"Another connection still open"]' . "\n");
44 1 $writer->write($message);
45 1 $writer->close;
46 1 return;
47 }
48  
49 $conn->write_cb(
50 3 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
51 3 my $conn = shift;
52 3 my ($message) = @_;
53  
54 3 $message = $self->_wrap_message($callback, $message);
55  
56 3 $writer->write($message);
57 3 $writer->write('');
58 3 $writer->close;
59  
60 3 ▶ $conn->reconnecting if $conn->is_connected;
Branch: 1 branch
BranchTrueFalseTotal
if $conn->is_connected 3 0 3
61 }
62 3 );
63  
64 3 ▶ if ($conn->is_closed) {
Branch: 2 branches
BranchTrueFalseTotal
if ($conn->is_closed) { } 1 2 3
elsif ($conn->is_connected) { } 0 2 2
65 1 $conn->connected;
66 1 $conn->close;
67 }
68 elsif ($conn->is_connected) {
69 0 $conn->reconnected;
70 }
71 else {
72 2 $conn->write('o');
73  
74 2 $conn->connected;
75 }
76 4 };
77 }
78  
79 4 ▶sub _wrap_message {
Subroutine _wrap_message: called CC=1 SCAR=0.0
80 4 my $self = shift;
81 4 my ($callback, $message) = @_;
82  
83 4 $message =~ s/(['""\\\/\n\r\t]{1})/\\$1/smg;
84 4 $message = qq{/**/$callback("$message");\r\n};
85  
86 4 return $message;
87 }
88  
89 1 1;
« SockJS/Transport/EventSource.pm ↑ Summary SockJS/Exception.pm »