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   862 use strict;
  16         32  
  16         578  
4 16     16   78 use warnings;
  16         29  
  16         394  
5              
6 16     16   72 use base 'Protocol::WebSocket::Cookie';
  16         28  
  16         6305  
7              
8             sub parse {
9 5     5 1 15 my $self = shift;
10              
11 5         17 $self->SUPER::parse(@_);
12              
13 5         7 my $cookies = [];
14              
15 5         6 my $version = 1;
16 5 50       13 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         7 my $cookie;
22 5         6 foreach my $pair (@{$self->pairs}) {
  5         10  
23 16 50       29 next unless defined $pair->[0];
24              
25 16 100       44 if ($pair->[0] =~ m/^[^\$]/) {
    100          
    100          
26 6 100       12 push @$cookies, $cookie if defined $cookie;
27              
28 6         11 $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         4 $cookie->domain($pair->[1]);
39             }
40             }
41              
42 5 50       11 push @$cookies, $cookie if defined $cookie;
43              
44 5         13 return $cookies;
45             }
46              
47 6 50   6 1 34 sub name { @_ > 1 ? $_[0]->{name} = $_[1] : $_[0]->{name} }
48 6 50   6 1 27 sub value { @_ > 1 ? $_[0]->{value} = $_[1] : $_[0]->{value} }
49 3 50   3 1 14 sub version { @_ > 1 ? $_[0]->{version} = $_[1] : $_[0]->{version} }
50 7 100   7 1 24 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   8 sub _build_cookie { shift; Protocol::WebSocket::Cookie::Request->new(@_) }
  6         12  
54              
55             1;
56             __END__