| 1 | package Apache::FakeCookie; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 1 | $VERSION = do { my @r = (q$Revision: 0.08 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; | |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||
| 6 | # Oh!, we really don't live in this package | ||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | package Apache::Cookie; | ||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use vars qw($Cookies); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||
| 12 | 1 | $Cookies = {}; | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | # emluation is fairly complete | ||||||||||||||||||||||||||||||||||||
| 15 | # cookies can be created, altered and removed | ||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||
| 17 | 10 | ▶ | sub fetch { return wantarray ? %{$Cookies} : $Cookies; } | ||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | sub path {&do_this;} | ||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | sub secure {&do_this;} | ||||||||||||||||||||||||||||||||||
|
Subroutine
secure: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | 18 | ▶ | sub name {&do_this;} | ||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | sub domain {&do_this;} | ||||||||||||||||||||||||||||||||||
|
Subroutine
domain: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=5 SCAR=17.2
| |||||||||||||||||||||||||||||||||||||
| 23 | 5 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | $self->{-value} = $val if defined $val; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | if (defined $self->{-value}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | return wantarray ? @{$self->{-value}} : $self->{-value}->[0] | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return wantarray ? () : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||
| 31 | 11 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.4
| |||||||||||||||||||||||||||||||||||||
| 32 | 11 | my $proto = shift; # bless into Apache::Cookie | |||||||||||||||||||||||||||||||||||
| 33 | 11 | shift; # waste reference to $r; | |||||||||||||||||||||||||||||||||||
| 34 | 11 | my @vals = @_; | |||||||||||||||||||||||||||||||||||
| 35 | 11 | my $self = {@vals}; | |||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||
| 37 | # make sure values are in array format | ||||||||||||||||||||||||||||||||||||
| 38 | 11 | my $val = $self->{-value};; | |||||||||||||||||||||||||||||||||||
| 39 | 11 | ▶ | if (defined $val) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 40 | 10 | $val = $self->{-value}; | |||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | if (ref($val) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 42 | 10 | @vals = @$val; | |||||||||||||||||||||||||||||||||||
| 43 | } elsif (ref($val) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||
| 44 | 0 | @vals = %$val; | |||||||||||||||||||||||||||||||||||
| 45 | } elsif (!ref($val)) { | ||||||||||||||||||||||||||||||||||||
| 46 | 0 | @vals = ($val); # it's a plain SCALAR | |||||||||||||||||||||||||||||||||||
| 47 | } # hmm.... must be a SCALAR ref or CODE ref | ||||||||||||||||||||||||||||||||||||
| 48 | 10 | $self->{-value} = [@vals]; | |||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||
| 50 | $self->{-expires} = _expires($self->{-expires}) | ||||||||||||||||||||||||||||||||||||
| 51 | 11 | ▶ | if exists $self->{-expires} && defined $self->{-expires}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"-expires"} and defined $self->{"-expires"}
MC/DC50%1/2
exists $self->{"-expires"} and defined $self->{"-expires"}
exists $self->{"-expires"}
defined $self->{"-expires"}
Truth table66%2/3
A and B
A= exists $self->{"-expires"}B= defined $self->{"-expires"}
| |||||||||||||||||||||||||||||||||||||
| 52 | 11 | bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 53 | 11 | return $self; | |||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||
| 55 | 8 | ▶ | sub bake { | ||||||||||||||||||||||||||||||||||
|
Subroutine
bake: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 56 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | if ( defined $self->{-value} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 58 | 7 | $Cookies->{$self->{-name}} = $self; | |||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||
| 60 | 1 | delete $Cookies->{$self->{-name}}; | |||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | sub parse { # adapted from CGI::Cookie v1.20 by Lincoln Stein | ||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||
| 64 | 3 | my ($self,$raw_cookie) = @_; | |||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | if ($raw_cookie) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||
| 67 | 2 | my %results; | |||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 2 | my(@pairs) = split("; ?",$raw_cookie); | |||||||||||||||||||||||||||||||||||
| 70 | 2 | foreach (@pairs) { | |||||||||||||||||||||||||||||||||||
| 71 | 3 | s/\s*(.*?)\s*/$1/; | |||||||||||||||||||||||||||||||||||
| 72 | 3 | my($key,$value) = split("=",$_,2); | |||||||||||||||||||||||||||||||||||
| 73 | # Some foreign cookies are not in name=value format, so ignore | ||||||||||||||||||||||||||||||||||||
| 74 | # them. | ||||||||||||||||||||||||||||||||||||
| 75 | 3 | ▶ | next if !defined($value); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 76 | 3 | my @values = (); | |||||||||||||||||||||||||||||||||||
| 77 | 3 | ▶ | if ($value ne '') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 78 | 3 | @values = map unescape($_),split(/[&;]/,$value.'&dmy'); | |||||||||||||||||||||||||||||||||||
| 79 | 3 | pop @values; | |||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||
| 81 | 3 | $key = unescape($key); | |||||||||||||||||||||||||||||||||||
| 82 | # A bug in Netscape can cause several cookies with same name to | ||||||||||||||||||||||||||||||||||||
| 83 | # appear. The FIRST one in HTTP_COOKIE is the most recent version. | ||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | $results{$key} ||= $self->new(undef,-name=>$key,-value=>\@values); | ||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$results{$key} ||= $self->new(undef, "-name", $key, "-value", \@values)
MC/DC0%0/2
$results{$key} ||= $self->new(undef, "-name", $key, "-value", \@values)
$results{$key}
$self->new(undef, "-name", $key, "-value", \@values)
Truth table33%1/3
A ||= B
A= $results{$key}B= $self->new(undef, "-name", $key, "-value", \@values)
| |||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||
| 86 | 2 | $self = \%results; | |||||||||||||||||||||||||||||||||||
| 87 | 2 | bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 88 | 2 | $Cookies = $self; | |||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||
| 90 | 3 | @_ = ($self); | |||||||||||||||||||||||||||||||||||
| 91 | 3 | goto &fetch; | |||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||
| 93 | 22 | ▶ | sub expires { | ||||||||||||||||||||||||||||||||||
|
Subroutine
expires: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||
| 94 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 95 | 22 | ▶ | $self->{-expires} = _expires(shift) | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 96 | if @_; | ||||||||||||||||||||||||||||||||||||
| 97 | return (exists $self->{-expires} && | ||||||||||||||||||||||||||||||||||||
| 98 | defined $self->{-expires}) | ||||||||||||||||||||||||||||||||||||
| 99 | 22 | ▶ | ? $self->{-expires} : undef; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"-expires"} and defined $self->{"-expires"}
MC/DC50%1/2
exists $self->{"-expires"} and defined $self->{"-expires"}
exists $self->{"-expires"}
defined $self->{"-expires"}
Truth table66%2/3
A and B
A= exists $self->{"-expires"}B= defined $self->{"-expires"}
| |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||
| 101 | # Adapted from CGI::Cookie v1.20 by Lincoln Stein | ||||||||||||||||||||||||||||||||||||
| 102 | # This internal routine creates date strings suitable for use in | ||||||||||||||||||||||||||||||||||||
| 103 | # cookies and HTTP headers. (They differ, unfortunately.) | ||||||||||||||||||||||||||||||||||||
| 104 | # Thanks to Mark Fisher for this. | ||||||||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | sub _expires { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_expires: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 106 | 7 | my($time) = @_; | |||||||||||||||||||||||||||||||||||
| 107 | 7 | my(@MON)=qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; | |||||||||||||||||||||||||||||||||||
| 108 | 7 | my(@WDAY) = qw/Sun Mon Tue Wed Thu Fri Sat/; | |||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | # pass through preformatted dates for the sake of expire_calc() | ||||||||||||||||||||||||||||||||||||
| 111 | 7 | $time = _expire_calc($time); | |||||||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | return $time unless $time =~ /^\d+$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 113 | 7 | my $sc = '-'; | |||||||||||||||||||||||||||||||||||
| 114 | 7 | my($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime($time); | |||||||||||||||||||||||||||||||||||
| 115 | 7 | $year += 1900; | |||||||||||||||||||||||||||||||||||
| 116 | 7 | return sprintf("%s, %02d$sc%s$sc%04d %02d:%02d:%02d GMT", | |||||||||||||||||||||||||||||||||||
| 117 | $WDAY[$wday],$mday,$MON[$mon],$year,$hour,$min,$sec); | ||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||
| 119 | # Copied directly from CGI::Cookie v1.20 by Lincoln Stein | ||||||||||||||||||||||||||||||||||||
| 120 | # This internal routine creates an expires time exactly some number of | ||||||||||||||||||||||||||||||||||||
| 121 | # hours from the current time. It incorporates modifications from | ||||||||||||||||||||||||||||||||||||
| 122 | # Mark Fisher. | ||||||||||||||||||||||||||||||||||||
| 123 | 7 | ▶ | sub _expire_calc { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_expire_calc: called CC=6 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||
| 124 | 7 | my($time) = @_; | |||||||||||||||||||||||||||||||||||
| 125 | 7 | my(%mult) = ('s'=>1, | |||||||||||||||||||||||||||||||||||
| 126 | 'm'=>60, | ||||||||||||||||||||||||||||||||||||
| 127 | 'h'=>60*60, | ||||||||||||||||||||||||||||||||||||
| 128 | 'd'=>60*60*24, | ||||||||||||||||||||||||||||||||||||
| 129 | 'M'=>60*60*24*30, | ||||||||||||||||||||||||||||||||||||
| 130 | 'y'=>60*60*24*365); | ||||||||||||||||||||||||||||||||||||
| 131 | # format for time can be in any of the forms... | ||||||||||||||||||||||||||||||||||||
| 132 | # "now" -- expire immediately | ||||||||||||||||||||||||||||||||||||
| 133 | # "+180s" -- in 180 seconds | ||||||||||||||||||||||||||||||||||||
| 134 | # "+2m" -- in 2 minutes | ||||||||||||||||||||||||||||||||||||
| 135 | # "+12h" -- in 12 hours | ||||||||||||||||||||||||||||||||||||
| 136 | # "+1d" -- in 1 day | ||||||||||||||||||||||||||||||||||||
| 137 | # "+3M" -- in 3 months | ||||||||||||||||||||||||||||||||||||
| 138 | # "+2y" -- in 2 years | ||||||||||||||||||||||||||||||||||||
| 139 | # "-3m" -- 3 minutes ago(!) | ||||||||||||||||||||||||||||||||||||
| 140 | # If you don't supply one of these forms, we assume you are | ||||||||||||||||||||||||||||||||||||
| 141 | # specifying the date yourself | ||||||||||||||||||||||||||||||||||||
| 142 | 7 | my($offset); | |||||||||||||||||||||||||||||||||||
| 143 | 7 | ▶ | if (!$time || (lc($time) eq 'now')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
not $time or lc $time eq "now"
MC/DC0%0/2
not $time or lc $time eq "now"
not $time
lc $time eq "now"
Truth table33%1/3
not(A) or B
A= not $timeB= lc $time eq "now"
| |||||||||||||||||||||||||||||||||||||
| 144 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||
| 145 | } elsif ($time=~/^\d+/) { | ||||||||||||||||||||||||||||||||||||
| 146 | 2 | return $time; | |||||||||||||||||||||||||||||||||||
| 147 | } elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([mhdMy]?)/) { | ||||||||||||||||||||||||||||||||||||
| 148 | 5 | ▶ | $offset = ($mult{$2} || 1)*$1; | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$mult{$2} || 1
MC/DC0%0/1
$mult{$2} || 1
$mult{$2}
Truth table50%1/2
A
A= $mult{$2}
| |||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $time; | |||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||
| 152 | 5 | return (time+$offset); | |||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||
| 155 | 3 | my ($self,$name) = @_; | |||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | if ($name) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | delete $Cookies->{$name} if exists $Cookies->{$name}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 158 | } else { | ||||||||||||||||||||||||||||||||||||
| 159 | delete $Cookies->{$self->{-name}} | ||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | if exists $Cookies->{$self->{-name}}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||
| 163 | 17 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||
| 164 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 165 | 17 | ▶ | return '' unless $self->name; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 166 | 17 | my %cook = %$self; | |||||||||||||||||||||||||||||||||||
| 167 | 17 | ▶ | my $cook = ($cook{-name}) ? escape($cook{-name}) . '=' : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 168 | 17 | ▶ | if ($cook{-value}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 169 | 17 | my $i = ''; | |||||||||||||||||||||||||||||||||||
| 170 | 17 | foreach(@{$cook{-value}}) { | |||||||||||||||||||||||||||||||||||
| 171 | 20 | $cook .= $i . escape($_); | |||||||||||||||||||||||||||||||||||
| 172 | 20 | $i = '&'; | |||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||
| 175 | 17 | foreach(qw(domain path)) { | |||||||||||||||||||||||||||||||||||
| 176 | 34 | ▶ | $cook .= "; $_=" . $cook{"-$_"} if $cook{"-$_"}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||
| 178 | 17 | ▶ | $cook .= "; expires=$_" if ($_ = expires(\%cook)); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 179 | 17 | ▶ | $cook .= ($cook{-secure}) ? '; secure' : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||
| 182 | ### helpers | ||||||||||||||||||||||||||||||||||||
| 183 | 30 | ▶ | sub do_this { | ||||||||||||||||||||||||||||||||||
|
Subroutine
do_this: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 184 | 30 | (caller(1))[3] =~ /[^:]+$/; | |||||||||||||||||||||||||||||||||||
| 185 | 30 | splice(@_,1,0,'-'.$&); | |||||||||||||||||||||||||||||||||||
| 186 | 30 | goto &cookie_item; | |||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||
| 188 | # get or set a named item in cookie hash | ||||||||||||||||||||||||||||||||||||
| 189 | 30 | ▶ | sub cookie_item { | ||||||||||||||||||||||||||||||||||
|
Subroutine
cookie_item: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||
| 190 | 30 | my($self,$item,$val) = @_; | |||||||||||||||||||||||||||||||||||
| 191 | 30 | ▶ | if ( defined $val ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 192 | # | ||||||||||||||||||||||||||||||||||||
| 193 | # Darn! this modifies a cookie item if user is generating | ||||||||||||||||||||||||||||||||||||
| 194 | # a replacement cookie and has not yet "baked" it... | ||||||||||||||||||||||||||||||||||||
| 195 | # Don't see how this can hurt in the real world... MAR 9-2-02 | ||||||||||||||||||||||||||||||||||||
| 196 | 4 | ▶ | if ( $item eq '-name' && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$item eq "-name" and exists $$Apache::Cookie::Cookies{$self->{"-name"}}
MC/DC50%1/2
$item eq "-name" and exists $$Apache::Cookie::Cookies{$self->{"-name"}}
$item eq "-name"
exists $$Apache::Cookie::Cookies{$self->{"-name"}}
Truth table66%2/3
A and B
A= $item eq "-name"B= exists $$Apache::Cookie::Cookies{$self->{"-name"}}
| |||||||||||||||||||||||||||||||||||||
| 197 | exists $Cookies->{$self->{-name}} ) { | ||||||||||||||||||||||||||||||||||||
| 198 | 1 | $Cookies->{$val} = $Cookies->{$self->{-name}}; | |||||||||||||||||||||||||||||||||||
| 199 | 1 | delete $Cookies->{$self->{-name}}; | |||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||
| 201 | 4 | $self->{$item} = $val; | |||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||
| 203 | 30 | ▶ | return (exists $self->{$item}) ? $self->{$item} : ''; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||
| 205 | 78 | ▶ | sub escape { | ||||||||||||||||||||||||||||||||||
|
Subroutine
escape: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||
| 206 | 78 | my ($x) = @_; | |||||||||||||||||||||||||||||||||||
| 207 | 78 | ▶ | return undef unless defined($x); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 208 | 78 | $x =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; | |||||||||||||||||||||||||||||||||||
| 209 | 78 | return $x; | |||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||
| 211 | # unescape URL-data, but leave +'s alone | ||||||||||||||||||||||||||||||||||||
| 212 | 12 | ▶ | sub unescape { | ||||||||||||||||||||||||||||||||||
|
Subroutine
unescape: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||
| 213 | 12 | my ($x) = @_; | |||||||||||||||||||||||||||||||||||
| 214 | 12 | ▶ | return undef unless defined($x); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 215 | 12 | $x =~ tr/+/ /; # pluses become spaces | |||||||||||||||||||||||||||||||||||
| 216 | 12 | $x =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; | |||||||||||||||||||||||||||||||||||
| 217 | 12 | return $x; | |||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||
| 219 | 1 | 1 | |||||||||||||||||||||||||||||||||||
| 220 | __END__ | ||||||||||||||||||||||||||||||||||||