File Coverage

blib/lib/Protocol/SocketIO/Handshake.pm
Criterion Covered Total %
statement 19 20 95.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 5 6 83.3
pod 2 2 100.0
total 29 32 90.6


line stmt bran cond sub pod time code
1             package Protocol::SocketIO::Handshake;
2              
3 1     1   416 use strict;
  1         1  
  1         22  
4 1     1   2 use warnings;
  1         1  
  1         39  
5              
6 1     1   3 use overload '""' => sub { $_[0]->to_bytes }, fallback => 1;
  1     0   6  
  1         5  
  0         0  
7              
8             sub new {
9 2     2 1 278 my $class = shift;
10              
11 2         6 my $self = bless {@_}, $class;
12              
13 2         3 return $self;
14             }
15              
16             sub to_bytes {
17 2     2 1 11 my $self = shift;
18              
19             $self->{transports}
20 2   100     27 ||= [qw/websocket flashsocket htmlfile xhr-polling jsonp-polling/];
21              
22 2         2 my $transports = join ',', @{$self->{transports}};
  2         4  
23              
24 2         4 for (qw/session_id heartbeat_timeout close_timeout/) {
25 6 50       10 die "$_ is required" unless defined $self->{$_};
26             }
27              
28             return join ':', $self->{session_id}, $self->{heartbeat_timeout},
29 2         9 $self->{close_timeout}, $transports;
30             }
31              
32             1;
33             __END__