GX/HTTP/Request/Cookie.pm

filter: Statementstmt 94.7% 54 / 57 Branchbran 80.5% 29 / 36 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 100% 2 / 2 totaltotal 86.5% 90 / 104 CC 20 SCAR 23.5
CC
20
Cov
88%
parse
13.3
as_string
8.2
BEGIN
1.0
CRAP 10.5
« GX/SQL/Builder/Pg.pm ↑ Summary GX/Route/Static/Compiled.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/HTTP/Request/Cookie.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::HTTP::Request::Cookie;
7  
8 16 ▶use GX::HTTP::Util qw( quote url_encode url_decode );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # ----------------------------------------------------------------------------------------------------------------------
12 # Class setup
13 # ----------------------------------------------------------------------------------------------------------------------
14  
15 16 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 16 extends 'GX::HTTP::Cookie';
18  
19 16 build;
20  
21  
22 # ----------------------------------------------------------------------------------------------------------------------
23 # Public methods
24 # ----------------------------------------------------------------------------------------------------------------------
25  
26 2 ▶sub as_string {
Subroutine as_string: called CC=8 SCAR=21.1
Pod documented
27  
28 2 my $self = shift;
29  
30 2 my $string = '';
31  
32 2 ▶ if ( ! defined $self->{'name'} || ! length $self->{'name'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"name"} and length $self->{"name"}) 0 2 2
Condition33%1/3
defined $self->{"name"} and length $self->{"name"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->{"name"} and length $self->{"name"}
defined $self->{"name"} length $self->{"name"}
Truth table33%1/3
A and B
A= defined $self->{"name"}B= length $self->{"name"}
ABresult
0X0
100
111
33 0 return $string;
34 }
35  
36 2 ▶ if ( defined $self->{'version'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'version'}) { } 1 1 2
37 1 $string .= '$Version=' . $self->{'version'} . '; ';
38 }
39 else {
40 1 $string .= '$Version=1; ';
41 }
42  
43 2 $string .= url_encode( $self->{'name'} ) . '=';
44  
45 2 ▶ if ( defined $self->{'value'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"value"}) 2 0 2
46 2 $string .= quote( $self->{'value'} );
47 }
48  
49 2 ▶ if ( defined $self->{'path'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"path"}) 1 1 2
50 1 $string .= '; $Path=' . $self->{'path'};
51 }
52  
53 2 ▶ if ( defined $self->{'domain'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"domain"}) 1 1 2
54 1 $string .= '; $Domain=' . $self->{'domain'};
55 }
56  
57 2 ▶ if ( defined $self->{'port'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"port"}) 1 1 2
58 # Must be quoted (RFC 2965)
59 1 $string .= '; $Port=' . quote( $self->{'port'} );
60 }
61  
62 2 return $string;
63  
64  
65 }
66  
67 5 ▶sub parse {
Subroutine parse: called CC=13 SCAR=25.9
Pod documented
68  
69 5 my $class = shift;
70 5 my $string = shift;
71  
72 5 ▶ defined $string or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $string or return 5 0 5
73  
74 5 my @parts;
75  
76 5 ▶ while ( length $string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string) 25 5 30
77  
78 25 ▶ $string =~ s/^\s*([^=;,]+)\s*=\s*// or return;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/^\s*([^=;,]+)\s*=\s*// or return 25 0 25
79  
80 25 push @parts, $1;
81  
82 25 ▶ if ( $string =~ s/^"([^"\\]*(?:\\.[^"\\]*)*)"\s*(?:;|,)*// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($string =~ s/^"([^"\\]*(?:\\.[^"\\]*)*)"\s*(?:;|,)*//) { } 21 4 25
elsif ($string =~ s/^([^;,]*)\s*(?:;|,)*//) { } 4 0 4
83 21 my $value = $1;
84 21 $value =~ s/\\"/"/g;
85 21 $value =~ s/\\\\/\\/g;
86 21 push @parts, $value;
87 }
88 elsif ( $string =~ s/^([^;,]*)\s*(?:;|,)*// ) {
89 4 push @parts, $1;
90 }
91 else {
92 0 return;
93 }
94  
95 }
96  
97 # See RFC 2109, section 4.4
98  
99 5 my @cookies;
100 my $cookie;
101 5 my %attributes;
102  
103 5 ▶ while ( @parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) 25 5 30
104  
105 25 my $part = shift @parts;
106  
107 25 ▶ if ( substr( $part, 0, 1 ) eq '$' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($part, 0, 1) eq '$') { } 16 9 25
108  
109 16 my $attribute = lc substr( $part, 1 );
110 16 my $value = shift @parts;
111  
112 16 ▶ if ( $cookie ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookie) { } 11 5 16
113  
114 11 ▶ if ( $attribute eq 'version' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($attribute eq 'version') { } 0 11 11
elsif ($attribute eq 'path') { } 9 2 11
elsif ($attribute eq 'domain') { } 1 1 2
elsif ($attribute eq 'port') { } 1 0 1
115 0 $cookie->{'version'} = $value;
116 }
117 elsif ( $attribute eq 'path' ) {
118 9 $cookie->{'path'} = $value;
119 }
120 elsif ( $attribute eq 'domain' ) {
121 1 $cookie->{'domain'} = $value;
122 }
123 elsif ( $attribute eq 'port' ) {
124 1 $cookie->{'port'} = $value;
125 }
126  
127 }
128 else {
129  
130 # Global attribute
131 5 $attributes{$attribute} = $value;
132  
133 }
134  
135 }
136 else {
137  
138 $cookie = $class->new(
139 name => url_decode( $part ),
140 value => shift( @parts ),
141 domain => $attributes{'domain'},
142 path => $attributes{'path'},
143 9 version => $attributes{'version'}
144 );
145  
146 9 push @cookies, $cookie;
147  
148 }
149  
150 }
151  
152 5 return @cookies;
153  
154 }
155  
156  
157 16 1;
158  
159 __END__
« GX/SQL/Builder/Pg.pm ↑ Summary GX/Route/Static/Compiled.pm »