Filename | /usr/share/perl/5.10/CGI/Cookie.pm |
Statements | Executed 276 statements in 2.21ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 2 | 2 | 215µs | 612µs | as_string | CGI::Cookie::
2 | 1 | 1 | 164µs | 387µs | new | CGI::Cookie::
11 | 1 | 1 | 104µs | 197µs | fetch | CGI::Cookie::
11 | 1 | 1 | 94µs | 94µs | get_raw_cookie | CGI::Cookie::
5 | 2 | 1 | 39µs | 39µs | path | CGI::Cookie::
1 | 1 | 1 | 31µs | 123µs | BEGIN@18 | CGI::Cookie::
3 | 1 | 1 | 27µs | 27µs | expires | CGI::Cookie::
6 | 2 | 1 | 26µs | 26µs | name | CGI::Cookie::
4 | 2 | 1 | 21µs | 21µs | httponly | CGI::Cookie::
3 | 1 | 1 | 20µs | 20µs | max_age | CGI::Cookie::
3 | 1 | 1 | 19µs | 19µs | value | CGI::Cookie::
1 | 1 | 1 | 19µs | 72µs | BEGIN@20 | CGI::Cookie::
3 | 1 | 1 | 14µs | 14µs | secure | CGI::Cookie::
3 | 1 | 1 | 13µs | 13µs | domain | CGI::Cookie::
1 | 1 | 1 | 11µs | 41µs | BEGIN@19 | CGI::Cookie::
0 | 0 | 0 | 0s | 0s | bake | CGI::Cookie::
0 | 0 | 0 | 0s | 0s | compare | CGI::Cookie::
0 | 0 | 0 | 0s | 0s | parse | CGI::Cookie::
0 | 0 | 0 | 0s | 0s | raw_fetch | CGI::Cookie::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package CGI::Cookie; | ||||
2 | |||||
3 | # See the bottom of this file for the POD documentation. Search for the | ||||
4 | # string '=head'. | ||||
5 | |||||
6 | # You can run this file through either pod2man or pod2html to produce pretty | ||||
7 | # documentation in manual or html file format (these utilities are part of the | ||||
8 | # Perl 5 distribution). | ||||
9 | |||||
10 | # Copyright 1995-1999, Lincoln D. Stein. All rights reserved. | ||||
11 | # It may be used and modified freely, but I do request that this copyright | ||||
12 | # notice remain attached to the file. You may modify this module as you | ||||
13 | # wish, but if you redistribute a modified version, please attach a note | ||||
14 | # listing the modifications you have made. | ||||
15 | |||||
16 | 1 | 800ns | $CGI::Cookie::VERSION='1.29'; | ||
17 | |||||
18 | 3 | 45µs | 2 | 215µs | # spent 123µs (31+92) within CGI::Cookie::BEGIN@18 which was called:
# once (31µs+92µs) by CGI::cookie at line 18 # spent 123µs making 1 call to CGI::Cookie::BEGIN@18
# spent 92µs making 1 call to Exporter::import |
19 | 3 | 45µs | 2 | 71µs | # spent 41µs (11+30) within CGI::Cookie::BEGIN@19 which was called:
# once (11µs+30µs) by CGI::cookie at line 19 # spent 41µs making 1 call to CGI::Cookie::BEGIN@19
# spent 30µs making 1 call to CGI::import |
20 | 1 | 52µs | # spent 72µs (19+53) within CGI::Cookie::BEGIN@20 which was called:
# once (19µs+53µs) by CGI::cookie at line 22 # spent 52µs making 1 call to overload::import | ||
21 | 'cmp' => \&compare, | ||||
22 | 3 | 1.35ms | 1 | 72µs | 'fallback'=>1; # spent 72µs making 1 call to CGI::Cookie::BEGIN@20 |
23 | |||||
24 | # Turn on special checking for Doug MacEachern's modperl | ||||
25 | 1 | 500ns | my $MOD_PERL = 0; | ||
26 | 1 | 2µs | if (exists $ENV{MOD_PERL}) { | ||
27 | if (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} == 2) { | ||||
28 | $MOD_PERL = 2; | ||||
29 | require Apache2::RequestUtil; | ||||
30 | require APR::Table; | ||||
31 | } else { | ||||
32 | $MOD_PERL = 1; | ||||
33 | require Apache; | ||||
34 | } | ||||
35 | } | ||||
36 | |||||
37 | # fetch a list of cookies from the environment and | ||||
38 | # return as a hash. the cookies are parsed as normal | ||||
39 | # escaped URL data. | ||||
40 | # spent 197µs (104+94) within CGI::Cookie::fetch which was called 11 times, avg 18µs/call:
# 11 times (104µs+94µs) by CGI::cookie at line 12 of (eval 1032)[CGI.pm:869], avg 18µs/call | ||||
41 | 22 | 90µs | my $class = shift; | ||
42 | 11 | 94µs | my $raw_cookie = get_raw_cookie(@_) or return; # spent 94µs making 11 calls to CGI::Cookie::get_raw_cookie, avg 9µs/call | ||
43 | return $class->parse($raw_cookie); | ||||
44 | } | ||||
45 | |||||
46 | # Fetch a list of cookies from the environment or the incoming headers and | ||||
47 | # return as a hash. The cookie values are not unescaped or altered in any way. | ||||
48 | sub raw_fetch { | ||||
49 | my $class = shift; | ||||
50 | my $raw_cookie = get_raw_cookie(@_) or return; | ||||
51 | my %results; | ||||
52 | my($key,$value); | ||||
53 | |||||
54 | my @pairs = split("[;,] ?",$raw_cookie); | ||||
55 | foreach (@pairs) { | ||||
56 | s/\s*(.*?)\s*/$1/; | ||||
57 | if (/^([^=]+)=(.*)/) { | ||||
58 | $key = $1; | ||||
59 | $value = $2; | ||||
60 | } | ||||
61 | else { | ||||
62 | $key = $_; | ||||
63 | $value = ''; | ||||
64 | } | ||||
65 | $results{$key} = $value; | ||||
66 | } | ||||
67 | return \%results unless wantarray; | ||||
68 | return %results; | ||||
69 | } | ||||
70 | |||||
71 | # spent 94µs within CGI::Cookie::get_raw_cookie which was called 11 times, avg 9µs/call:
# 11 times (94µs+0s) by CGI::Cookie::fetch at line 42, avg 9µs/call | ||||
72 | 33 | 73µs | my $r = shift; | ||
73 | $r ||= eval { $MOD_PERL == 2 ? | ||||
74 | Apache2::RequestUtil->request() : | ||||
75 | Apache->request } if $MOD_PERL; | ||||
76 | 22 | 42µs | if ($r) { | ||
77 | $raw_cookie = $r->headers_in->{'Cookie'}; | ||||
78 | } else { | ||||
79 | if ($MOD_PERL && !exists $ENV{REQUEST_METHOD}) { | ||||
80 | die "Run $r->subprocess_env; before calling fetch()"; | ||||
81 | } | ||||
82 | $raw_cookie = $ENV{HTTP_COOKIE} || $ENV{COOKIE}; | ||||
83 | } | ||||
84 | } | ||||
85 | |||||
86 | |||||
87 | sub parse { | ||||
88 | my ($self,$raw_cookie) = @_; | ||||
89 | my %results; | ||||
90 | |||||
91 | my @pairs = split("[;,] ?",$raw_cookie); | ||||
92 | foreach (@pairs) { | ||||
93 | s/\s*(.*?)\s*/$1/; | ||||
94 | my($key,$value) = split("=",$_,2); | ||||
95 | |||||
96 | # Some foreign cookies are not in name=value format, so ignore | ||||
97 | # them. | ||||
98 | next if !defined($value); | ||||
99 | my @values = (); | ||||
100 | if ($value ne '') { | ||||
101 | @values = map unescape($_),split(/[&;]/,$value.'&dmy'); | ||||
102 | pop @values; | ||||
103 | } | ||||
104 | $key = unescape($key); | ||||
105 | # A bug in Netscape can cause several cookies with same name to | ||||
106 | # appear. The FIRST one in HTTP_COOKIE is the most recent version. | ||||
107 | $results{$key} ||= $self->new(-name=>$key,-value=>\@values); | ||||
108 | } | ||||
109 | return \%results unless wantarray; | ||||
110 | return %results; | ||||
111 | } | ||||
112 | |||||
113 | # spent 387µs (164+223) within CGI::Cookie::new which was called 2 times, avg 193µs/call:
# 2 times (164µs+223µs) by CGI::cookie at line 34 of (eval 1032)[CGI.pm:869], avg 193µs/call | ||||
114 | 28 | 145µs | my $class = shift; | ||
115 | $class = ref($class) if ref($class); | ||||
116 | # Ignore mod_perl request object--compatability with Apache::Cookie. | ||||
117 | shift if ref $_[0] | ||||
118 | && eval { $_[0]->isa('Apache::Request::Req') || $_[0]->isa('Apache') }; | ||||
119 | 2 | 193µs | my($name,$value,$path,$domain,$secure,$expires,$httponly) = # spent 193µs making 2 calls to CGI::Util::rearrange, avg 97µs/call | ||
120 | rearrange([NAME,[VALUE,VALUES],PATH,DOMAIN,SECURE,EXPIRES,HTTPONLY],@_); | ||||
121 | |||||
122 | # Pull out our parameters. | ||||
123 | my @values; | ||||
124 | 2 | 4µs | if (ref($value)) { | ||
125 | if (ref($value) eq 'ARRAY') { | ||||
126 | @values = @$value; | ||||
127 | } elsif (ref($value) eq 'HASH') { | ||||
128 | @values = %$value; | ||||
129 | } | ||||
130 | } else { | ||||
131 | @values = ($value); | ||||
132 | } | ||||
133 | |||||
134 | bless my $self = { | ||||
135 | 'name'=>$name, | ||||
136 | 'value'=>[@values], | ||||
137 | },$class; | ||||
138 | |||||
139 | # IE requires the path and domain to be present for some reason. | ||||
140 | $path ||= "/"; | ||||
141 | # however, this breaks networks which use host tables without fully qualified | ||||
142 | # names, so we comment it out. | ||||
143 | # $domain = CGI::virtual_host() unless defined $domain; | ||||
144 | |||||
145 | 2 | 23µs | $self->path($path) if defined $path; # spent 23µs making 2 calls to CGI::Cookie::path, avg 11µs/call | ||
146 | $self->domain($domain) if defined $domain; | ||||
147 | $self->secure($secure) if defined $secure; | ||||
148 | $self->expires($expires) if defined $expires; | ||||
149 | 1 | 7µs | $self->httponly($httponly) if defined $httponly; # spent 7µs making 1 call to CGI::Cookie::httponly | ||
150 | # $self->max_age($expires) if defined $expires; | ||||
151 | return $self; | ||||
152 | } | ||||
153 | |||||
154 | # spent 612µs (215+397) within CGI::Cookie::as_string which was called 3 times, avg 204µs/call:
# 2 times (101µs+267µs) by CGI::header at line 17 of (eval 1131)[CGI.pm:869], avg 184µs/call
# once (114µs+129µs) by C4::Auth::checkauth at line 1034 of /usr/share/koha/lib/C4/Auth.pm | ||||
155 | 36 | 169µs | my $self = shift; | ||
156 | 3 | 17µs | return "" unless $self->name; # spent 17µs making 3 calls to CGI::Cookie::name, avg 6µs/call | ||
157 | |||||
158 | my(@constant_values,$domain,$path,$expires,$max_age,$secure,$httponly); | ||||
159 | |||||
160 | 3 | 13µs | push(@constant_values,"domain=$domain") if $domain = $self->domain; # spent 13µs making 3 calls to CGI::Cookie::domain, avg 4µs/call | ||
161 | 3 | 16µs | push(@constant_values,"path=$path") if $path = $self->path; # spent 16µs making 3 calls to CGI::Cookie::path, avg 5µs/call | ||
162 | 3 | 27µs | push(@constant_values,"expires=$expires") if $expires = $self->expires; # spent 27µs making 3 calls to CGI::Cookie::expires, avg 9µs/call | ||
163 | 3 | 20µs | push(@constant_values,"max-age=$max_age") if $max_age = $self->max_age; # spent 20µs making 3 calls to CGI::Cookie::max_age, avg 6µs/call | ||
164 | 3 | 14µs | push(@constant_values,"secure") if $secure = $self->secure; # spent 14µs making 3 calls to CGI::Cookie::secure, avg 5µs/call | ||
165 | 3 | 13µs | push(@constant_values,"HttpOnly") if $httponly = $self->httponly; # spent 13µs making 3 calls to CGI::Cookie::httponly, avg 4µs/call | ||
166 | |||||
167 | 6 | 90µs | my($key) = escape($self->name); # spent 81µs making 3 calls to CGI::Util::escape, avg 27µs/call
# spent 9µs making 3 calls to CGI::Cookie::name, avg 3µs/call | ||
168 | 6 | 187µs | my($cookie) = join("=",(defined $key ? $key : ''),join("&",map escape(defined $_ ? $_ : ''),$self->value)); # spent 168µs making 3 calls to CGI::Util::escape, avg 56µs/call
# spent 19µs making 3 calls to CGI::Cookie::value, avg 6µs/call | ||
169 | return join("; ",$cookie,@constant_values); | ||||
170 | } | ||||
171 | |||||
172 | sub compare { | ||||
173 | my $self = shift; | ||||
174 | my $value = shift; | ||||
175 | return "$self" cmp $value; | ||||
176 | } | ||||
177 | |||||
178 | sub bake { | ||||
179 | my ($self, $r) = @_; | ||||
180 | |||||
181 | $r ||= eval { | ||||
182 | $MOD_PERL == 2 | ||||
183 | ? Apache2::RequestUtil->request() | ||||
184 | : Apache->request | ||||
185 | } if $MOD_PERL; | ||||
186 | if ($r) { | ||||
187 | $r->headers_out->add('Set-Cookie' => $self->as_string); | ||||
188 | } else { | ||||
189 | print CGI::header(-cookie => $self); | ||||
190 | } | ||||
191 | |||||
192 | } | ||||
193 | |||||
194 | # accessors | ||||
195 | sub name { | ||||
196 | 24 | 40µs | my $self = shift; | ||
197 | my $name = shift; | ||||
198 | $self->{'name'} = $name if defined $name; | ||||
199 | return $self->{'name'}; | ||||
200 | } | ||||
201 | |||||
202 | # spent 19µs within CGI::Cookie::value which was called 3 times, avg 6µs/call:
# 3 times (19µs+0s) by CGI::Cookie::as_string at line 168, avg 6µs/call | ||||
203 | 12 | 25µs | my $self = shift; | ||
204 | my $value = shift; | ||||
205 | if (defined $value) { | ||||
206 | my @values; | ||||
207 | if (ref($value)) { | ||||
208 | if (ref($value) eq 'ARRAY') { | ||||
209 | @values = @$value; | ||||
210 | } elsif (ref($value) eq 'HASH') { | ||||
211 | @values = %$value; | ||||
212 | } | ||||
213 | } else { | ||||
214 | @values = ($value); | ||||
215 | } | ||||
216 | $self->{'value'} = [@values]; | ||||
217 | } | ||||
218 | return wantarray ? @{$self->{'value'}} : $self->{'value'}->[0] | ||||
219 | } | ||||
220 | |||||
221 | # spent 13µs within CGI::Cookie::domain which was called 3 times, avg 4µs/call:
# 3 times (13µs+0s) by CGI::Cookie::as_string at line 160, avg 4µs/call | ||||
222 | 12 | 18µs | my $self = shift; | ||
223 | my $domain = shift; | ||||
224 | $self->{'domain'} = lc $domain if defined $domain; | ||||
225 | return $self->{'domain'}; | ||||
226 | } | ||||
227 | |||||
228 | # spent 14µs within CGI::Cookie::secure which was called 3 times, avg 5µs/call:
# 3 times (14µs+0s) by CGI::Cookie::as_string at line 164, avg 5µs/call | ||||
229 | 12 | 18µs | my $self = shift; | ||
230 | my $secure = shift; | ||||
231 | $self->{'secure'} = $secure if defined $secure; | ||||
232 | return $self->{'secure'}; | ||||
233 | } | ||||
234 | |||||
235 | # spent 27µs within CGI::Cookie::expires which was called 3 times, avg 9µs/call:
# 3 times (27µs+0s) by CGI::Cookie::as_string at line 162, avg 9µs/call | ||||
236 | 12 | 27µs | my $self = shift; | ||
237 | my $expires = shift; | ||||
238 | $self->{'expires'} = CGI::Util::expires($expires,'cookie') if defined $expires; | ||||
239 | return $self->{'expires'}; | ||||
240 | } | ||||
241 | |||||
242 | # spent 20µs within CGI::Cookie::max_age which was called 3 times, avg 6µs/call:
# 3 times (20µs+0s) by CGI::Cookie::as_string at line 163, avg 6µs/call | ||||
243 | 12 | 26µs | my $self = shift; | ||
244 | my $expires = shift; | ||||
245 | $self->{'max-age'} = CGI::Util::expire_calc($expires)-time() if defined $expires; | ||||
246 | return $self->{'max-age'}; | ||||
247 | } | ||||
248 | |||||
249 | sub path { | ||||
250 | 20 | 49µs | my $self = shift; | ||
251 | my $path = shift; | ||||
252 | $self->{'path'} = $path if defined $path; | ||||
253 | return $self->{'path'}; | ||||
254 | } | ||||
255 | |||||
256 | |||||
257 | sub httponly { # HttpOnly | ||||
258 | 16 | 27µs | my $self = shift; | ||
259 | my $httponly = shift; | ||||
260 | $self->{'httponly'} = $httponly if defined $httponly; | ||||
261 | return $self->{'httponly'}; | ||||
262 | } | ||||
263 | |||||
264 | 1 | 7µs | 1; | ||
265 | |||||
266 | =head1 NAME | ||||
267 | |||||
- - |