File Coverage

blib/lib/Protocol/WebSocket/Cookie/Request.pm
Criterion Covered Total %
statement 32 35 91.4
branch 18 24 75.0
condition n/a
subroutine 10 10 100.0
pod 6 6 100.0
total 66 75 88.0


line stmt bran cond sub pod time code
1             package Protocol::WebSocket::Cookie::Request;
2              
3 16     16   771 use strict;
  16         34  
  16         415  
4 16     16   74 use warnings;
  16         34  
  16         401  
5              
6 16     16   86 use base 'Protocol::WebSocket::Cookie';
  16         33  
  16         4798  
7              
8             sub parse {
9 5     5 1 17 my $self = shift;
10              
11 5         18 $self->SUPER::parse(@_);
12              
13 5         6 my $cookies = [];
14              
15 5         8 my $version = 1;
16 5 50       14 if ($self->pairs->[0] eq '$Version') {
17 0         0 my $pair = shift @{$self->pairs};
  0         0  
18 0         0 $version = $pair->[1];
19             }
20              
21 5         10 my $cookie;
22 5         7 foreach my $pair (@{$self->pairs}) {
  5         11  
23 16 50       32 next unless defined $pair->[0];
24              
25 16 100       55 if ($pair->[0] =~ m/^[^\$]/) {
    100          
    100          
26 6 100       13 push @$cookies, $cookie if defined $cookie;
27              
28 6         15 $cookie = $self->_build_cookie(
29             name => $pair->[0],
30             value => $pair->[1],
31             version => $version
32             );
33             }
34             elsif ($pair->[0] eq '$Path') {
35 3         6 $cookie->path($pair->[1]);
36             }
37             elsif ($pair->[0] eq '$Domain') {
38 3         6 $cookie->domain($pair->[1]);
39             }
40             }
41              
42 5 50       13 push @$cookies, $cookie if defined $cookie;
43              
44 5         19 return $cookies;
45             }
46              
47 6 50   6 1 39 sub name { @_ > 1 ? $_[0]->{name} = $_[1] : $_[0]->{name} }
48 6 50   6 1 32 sub value { @_ > 1 ? $_[0]->{value} = $_[1] : $_[0]->{value} }
49 3 50   3 1 13 sub version { @_ > 1 ? $_[0]->{version} = $_[1] : $_[0]->{version} }
50 7 100   7 1 31 sub path { @_ > 1 ? $_[0]->{path} = $_[1] : $_[0]->{path} }
51 7 100   7 1 25 sub domain { @_ > 1 ? $_[0]->{domain} = $_[1] : $_[0]->{domain} }
52              
53 6     6   9 sub _build_cookie { shift; Protocol::WebSocket::Cookie::Request->new(@_) }
  6         17  
54              
55             1;
56             __END__