WebSocket/Cookie.pm

filter: Statementstmt 100% 42 / 42 Branchbran 92.8% 13 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 98.5% 70 / 71 CC 10 SCAR 12.2
CC
10
Cov
98%
parse
5.0
to_string
4.0
new
2.0
CRAP 3.4
« WebSocket/Client.pm ↑ Summary WebSocket/Stateful.pm »
1 package Protocol::WebSocket::Cookie;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 58 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
7 58 my $class = shift;
8 58 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 58 58
9  
10 58 my $self = {@_};
11 58 bless $self, $class;
12  
13 58 return $self;
14 }
15  
16 75 ▶sub pairs { @_ > 1 ? $_[0]->{pairs} = $_[1] : $_[0]->{pairs} }
Subroutine pairs: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 20 55 75
17  
18 21 my $TOKEN = qr/[^;,\s"]+/;
19 21 my $NAME = qr/[^;,\s"=]+/;
20 21 my $QUOTED_STRING = qr/"(?:\\"|[^"])+"/;
21 21 my $VALUE = qr/(?:$TOKEN|$QUOTED_STRING)/;
22  
23 26 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
24 26 my $self = shift;
25 26 my $string = shift;
26  
27 26 $self->{pairs} = [];
28  
29 26 ▶ return unless defined $string && $string ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string and $string ne "" 2 24 26
Condition100%3/3
defined $string and $string ne ""
!ll&&!rl&&r
1124
MC/DC100%2/2
defined $string and $string ne ""
defined $string $string ne ""
Truth table100%3/3
A and B
A= defined $stringB= $string ne ""
ABresult
0X0
100
111
30  
31 24 ▶ while ($string =~ m/\s*($NAME)\s*(?:=\s*($VALUE))?;?/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /\s*($NAME)\s*(?:=\s*($VALUE))?;?/g) 52 24 76
32 52 my ($attr, $value) = ($1, $2);
33 52 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 51 1 52
34 51 $value =~ s/^"//;
35 51 $value =~ s/"$//;
36 51 $value =~ s/\\"/"/g;
37 }
38 52 push @{$self->{pairs}}, [$attr, $value];
39 }
40  
41 24 return $self;
42 }
43  
44 36 ▶sub to_string {
Subroutine to_string: called CC=4 SCAR=13.9
Pod documented
45 36 my $self = shift;
46  
47 36 my $string = '';
48  
49 36 my @pairs;
50 36 foreach my $pair (@{$self->pairs}) {
51 91 my $string = '';
52 91 $string .= $pair->[0];
53  
54 91 ▶ if (defined $pair->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pair->[1]) 89 2 91
55 89 $string .= '=';
56 89 ▶ $string
Branch: 1 branch
BranchTrueFalseTotal
!($pair->[1] =~ /^$VALUE$/) ? : 1 88 89
57 .= $pair->[1] !~ m/^$VALUE$/ ? "\"$pair->[1]\"" : $pair->[1];
58 }
59  
60 91 push @pairs, $string;
61 }
62  
63 36 return join '; ' => @pairs;
64 }
65  
66 21 1;
67 __END__
« WebSocket/Client.pm ↑ Summary WebSocket/Stateful.pm »