| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $string and $string ne ""
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 ""
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 24 | ▶ | while ($string =~ m/\s*($NAME)\s*(?:=\s*($VALUE))?;?/g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 52 | my ($attr, $value) = ($1, $2); | |||||||||||||||||||||||||||
| 33 | 52 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 55 | 89 | $string .= '='; | |||||||||||||||||||||||||||
| 56 | 89 | ▶ | $string | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||