File Coverage

blib/lib/Protocol/SocketIO/Path.pm
Criterion Covered Total %
statement 30 34 88.2
branch 9 10 90.0
condition 10 17 58.8
subroutine 6 8 75.0
pod 6 6 100.0
total 61 75 81.3


line stmt bran cond sub pod time code
1             package Protocol::SocketIO::Path;
2              
3 1     1   1394 use strict;
  1         2  
  1         107  
4 1     1   6 use warnings;
  1         1  
  1         414  
5              
6             sub new {
7 7     7 1 2647 my $class = shift;
8              
9 7         25 my $self = bless {@_}, $class;
10              
11 7   50     69 $self->{transports}
12             ||= [qw/websocket flashsocket htmlfile xhr-polling jsonp-polling/];
13              
14 7         30 return $self;
15             }
16              
17             sub parse {
18 7     7 1 11 my $self = shift;
19 7         12 my ($path) = @_;
20              
21 7         27 $path =~ s{^/}{};
22 7         15 $path =~ s{^$}{};
23              
24 7         24 my ($protocol_version, $transport_type, $session_id) = split '/',
25             $path, 3;
26 7 100 66     53 return unless $protocol_version && $protocol_version =~ m/^\d+$/;
27              
28             return
29 6 50 66     46 unless ($transport_type && $session_id)
      33        
      66        
30             || (!$transport_type && !$session_id);
31              
32 6 100       14 if ($transport_type) {
33 3 100       7 return unless grep { $transport_type eq $_ } @{$self->{transports}};
  15         34  
  3         6  
34             }
35              
36 5         19 $self->{protocol_version} = $protocol_version;
37 5         9 $self->{transport_type} = $transport_type;
38 5         7 $self->{session_id} = $session_id;
39              
40 5         15 return $self;
41             }
42              
43             sub protocol_version {
44 1     1 1 8 my $self = shift;
45              
46 1         7 return $self->{protocol_version};
47             }
48              
49             sub is_handshake {
50 2     2 1 13 my $self = shift;
51              
52 2 100 66     18 return 0
53             if defined $self->{transport_type} && defined $self->{session_id};
54              
55 1         5 return 1;
56             }
57              
58             sub session_id {
59 0     0 1   my $self = shift;
60              
61 0           return $self->{session_id};
62             }
63              
64             sub transport_type {
65 0     0 1   my $self = shift;
66              
67 0           return $self->{transport_type};
68             }
69              
70             1;
71             __END__