Filename | /usr/share/perl/5.10/CGI/Cookie.pm |
Statements | Executed 276 statements in 3.11ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 2 | 2 | 289µs | 949µs | as_string | CGI::Cookie::
11 | 1 | 1 | 118µs | 208µs | fetch | CGI::Cookie::
2 | 1 | 1 | 99µs | 215µs | new | CGI::Cookie::
11 | 1 | 1 | 90µs | 90µs | get_raw_cookie | CGI::Cookie::
1 | 1 | 1 | 38µs | 139µs | BEGIN@18 | CGI::Cookie::
6 | 2 | 1 | 30µs | 30µs | name | CGI::Cookie::
5 | 2 | 1 | 29µs | 29µs | path | CGI::Cookie::
1 | 1 | 1 | 27µs | 107µs | BEGIN@20 | CGI::Cookie::
3 | 1 | 1 | 25µs | 25µs | value | CGI::Cookie::
4 | 2 | 1 | 22µs | 22µs | httponly | CGI::Cookie::
1 | 1 | 1 | 18µs | 65µs | BEGIN@19 | CGI::Cookie::
3 | 1 | 1 | 16µs | 16µs | max_age | CGI::Cookie::
3 | 1 | 1 | 16µs | 16µs | domain | CGI::Cookie::
3 | 1 | 1 | 15µs | 15µs | expires | CGI::Cookie::
3 | 1 | 1 | 14µs | 14µs | secure | 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 | 2µs | $CGI::Cookie::VERSION='1.29'; | ||
17 | |||||
18 | 3 | 56µs | 2 | 241µs | # spent 139µs (38+102) within CGI::Cookie::BEGIN@18 which was called:
# once (38µs+102µs) by CGI::cookie at line 18 # spent 139µs making 1 call to CGI::Cookie::BEGIN@18
# spent 102µs making 1 call to Exporter::import |
19 | 3 | 68µs | 2 | 112µs | # spent 65µs (18+47) within CGI::Cookie::BEGIN@19 which was called:
# once (18µs+47µs) by CGI::cookie at line 19 # spent 65µs making 1 call to CGI::Cookie::BEGIN@19
# spent 47µs making 1 call to CGI::import |
20 | 1 | 23µs | 1 | 80µs | # spent 107µs (27+80) within CGI::Cookie::BEGIN@20 which was called:
# once (27µs+80µs) by CGI::cookie at line 22 # spent 80µs making 1 call to overload::import |
21 | 'cmp' => \&compare, | ||||
22 | 2 | 2.17ms | 1 | 107µs | 'fallback'=>1; # spent 107µs making 1 call to CGI::Cookie::BEGIN@20 |
23 | |||||
24 | # Turn on special checking for Doug MacEachern's modperl | ||||
25 | 1 | 900ns | my $MOD_PERL = 0; | ||
26 | 1 | 4µ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 208µs (118+90) within CGI::Cookie::fetch which was called 11 times, avg 19µs/call:
# 11 times (118µs+90µs) by CGI::cookie at line 12 of (eval 1049)[CGI.pm:869], avg 19µs/call | ||||
41 | 11 | 14µs | my $class = shift; | ||
42 | 11 | 73µs | 11 | 90µs | my $raw_cookie = get_raw_cookie(@_) or return; # spent 90µs making 11 calls to CGI::Cookie::get_raw_cookie, avg 8µ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 90µs within CGI::Cookie::get_raw_cookie which was called 11 times, avg 8µs/call:
# 11 times (90µs+0s) by CGI::Cookie::fetch at line 42, avg 8µs/call | ||||
72 | 11 | 9µs | my $r = shift; | ||
73 | 11 | 6µs | $r ||= eval { $MOD_PERL == 2 ? | ||
74 | Apache2::RequestUtil->request() : | ||||
75 | Apache->request } if $MOD_PERL; | ||||
76 | 11 | 68µs | if ($r) { | ||
77 | $raw_cookie = $r->headers_in->{'Cookie'}; | ||||
78 | } else { | ||||
79 | 11 | 6µs | if ($MOD_PERL && !exists $ENV{REQUEST_METHOD}) { | ||
80 | die "Run $r->subprocess_env; before calling fetch()"; | ||||
81 | } | ||||
82 | 11 | 33µs | $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 215µs (99+116) within CGI::Cookie::new which was called 2 times, avg 108µs/call:
# 2 times (99µs+116µs) by CGI::cookie at line 34 of (eval 1049)[CGI.pm:869], avg 108µs/call | ||||
114 | 2 | 2µs | my $class = shift; | ||
115 | 2 | 2µs | $class = ref($class) if ref($class); | ||
116 | # Ignore mod_perl request object--compatability with Apache::Cookie. | ||||
117 | shift if ref $_[0] | ||||
118 | 2 | 2µs | && eval { $_[0]->isa('Apache::Request::Req') || $_[0]->isa('Apache') }; | ||
119 | 2 | 16µs | 2 | 98µs | my($name,$value,$path,$domain,$secure,$expires,$httponly) = # spent 98µs making 2 calls to CGI::Util::rearrange, avg 49µs/call |
120 | rearrange([NAME,[VALUE,VALUES],PATH,DOMAIN,SECURE,EXPIRES,HTTPONLY],@_); | ||||
121 | |||||
122 | # Pull out our parameters. | ||||
123 | 2 | 800ns | my @values; | ||
124 | 2 | 2µ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 | 2 | 2µs | @values = ($value); | ||
132 | } | ||||
133 | |||||
134 | 2 | 45µs | 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 | 2 | 2µs | $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 | 8µs | 2 | 12µs | $self->path($path) if defined $path; # spent 12µs making 2 calls to CGI::Cookie::path, avg 6µs/call |
146 | 2 | 600ns | $self->domain($domain) if defined $domain; | ||
147 | 2 | 900ns | $self->secure($secure) if defined $secure; | ||
148 | 2 | 800ns | $self->expires($expires) if defined $expires; | ||
149 | 2 | 4µs | 1 | 6µs | $self->httponly($httponly) if defined $httponly; # spent 6µs making 1 call to CGI::Cookie::httponly |
150 | # $self->max_age($expires) if defined $expires; | ||||
151 | 2 | 13µs | return $self; | ||
152 | } | ||||
153 | |||||
154 | # spent 949µs (289+661) within CGI::Cookie::as_string which was called 3 times, avg 316µs/call:
# 2 times (213µs+577µs) by CGI::header at line 17 of (eval 1149)[CGI.pm:869], avg 395µs/call
# once (76µs+84µs) by C4::Auth::checkauth at line 1033 of /usr/share/koha/lib/C4/Auth.pm | ||||
155 | 3 | 3µs | my $self = shift; | ||
156 | 3 | 11µs | 3 | 18µs | return "" unless $self->name; # spent 18µs making 3 calls to CGI::Cookie::name, avg 6µs/call |
157 | |||||
158 | 3 | 4µs | my(@constant_values,$domain,$path,$expires,$max_age,$secure,$httponly); | ||
159 | |||||
160 | 3 | 13µs | 3 | 16µs | push(@constant_values,"domain=$domain") if $domain = $self->domain; # spent 16µs making 3 calls to CGI::Cookie::domain, avg 5µs/call |
161 | 3 | 18µs | 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 | 11µs | 3 | 15µs | push(@constant_values,"expires=$expires") if $expires = $self->expires; # spent 15µs making 3 calls to CGI::Cookie::expires, avg 5µs/call |
163 | 3 | 10µs | 3 | 16µs | push(@constant_values,"max-age=$max_age") if $max_age = $self->max_age; # spent 16µs making 3 calls to CGI::Cookie::max_age, avg 5µs/call |
164 | 3 | 11µs | 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 | 3 | 17µs | push(@constant_values,"HttpOnly") if $httponly = $self->httponly; # spent 17µs making 3 calls to CGI::Cookie::httponly, avg 6µs/call |
166 | |||||
167 | 3 | 25µs | 6 | 97µs | my($key) = escape($self->name); # spent 85µs making 3 calls to CGI::Util::escape, avg 28µs/call
# spent 13µs making 3 calls to CGI::Cookie::name, avg 4µs/call |
168 | 3 | 39µs | 6 | 451µs | my($cookie) = join("=",(defined $key ? $key : ''),join("&",map escape(defined $_ ? $_ : ''),$self->value)); # spent 427µs making 3 calls to CGI::Util::escape, avg 142µs/call
# spent 25µs making 3 calls to CGI::Cookie::value, avg 8µs/call |
169 | 3 | 26µs | 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 | 6 | 4µs | my $self = shift; | ||
197 | 6 | 3µs | my $name = shift; | ||
198 | 6 | 2µs | $self->{'name'} = $name if defined $name; | ||
199 | 6 | 35µs | return $self->{'name'}; | ||
200 | } | ||||
201 | |||||
202 | # spent 25µs within CGI::Cookie::value which was called 3 times, avg 8µs/call:
# 3 times (25µs+0s) by CGI::Cookie::as_string at line 168, avg 8µs/call | ||||
203 | 3 | 2µs | my $self = shift; | ||
204 | 3 | 2µs | my $value = shift; | ||
205 | 3 | 2µs | 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 | 3 | 23µs | return wantarray ? @{$self->{'value'}} : $self->{'value'}->[0] | ||
219 | } | ||||
220 | |||||
221 | # spent 16µs within CGI::Cookie::domain which was called 3 times, avg 5µs/call:
# 3 times (16µs+0s) by CGI::Cookie::as_string at line 160, avg 5µs/call | ||||
222 | 3 | 2µs | my $self = shift; | ||
223 | 3 | 2µs | my $domain = shift; | ||
224 | 3 | 1µs | $self->{'domain'} = lc $domain if defined $domain; | ||
225 | 3 | 16µs | 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 | 3 | 2µs | my $self = shift; | ||
230 | 3 | 2µs | my $secure = shift; | ||
231 | 3 | 1µs | $self->{'secure'} = $secure if defined $secure; | ||
232 | 3 | 71µs | return $self->{'secure'}; | ||
233 | } | ||||
234 | |||||
235 | # spent 15µs within CGI::Cookie::expires which was called 3 times, avg 5µs/call:
# 3 times (15µs+0s) by CGI::Cookie::as_string at line 162, avg 5µs/call | ||||
236 | 3 | 3µs | my $self = shift; | ||
237 | 3 | 2µs | my $expires = shift; | ||
238 | 3 | 1µs | $self->{'expires'} = CGI::Util::expires($expires,'cookie') if defined $expires; | ||
239 | 3 | 13µs | return $self->{'expires'}; | ||
240 | } | ||||
241 | |||||
242 | # spent 16µs within CGI::Cookie::max_age which was called 3 times, avg 5µs/call:
# 3 times (16µs+0s) by CGI::Cookie::as_string at line 163, avg 5µs/call | ||||
243 | 3 | 3µs | my $self = shift; | ||
244 | 3 | 2µs | my $expires = shift; | ||
245 | 3 | 2µs | $self->{'max-age'} = CGI::Util::expire_calc($expires)-time() if defined $expires; | ||
246 | 3 | 15µs | return $self->{'max-age'}; | ||
247 | } | ||||
248 | |||||
249 | sub path { | ||||
250 | 5 | 4µs | my $self = shift; | ||
251 | 5 | 3µs | my $path = shift; | ||
252 | 5 | 5µs | $self->{'path'} = $path if defined $path; | ||
253 | 5 | 24µs | return $self->{'path'}; | ||
254 | } | ||||
255 | |||||
256 | |||||
257 | sub httponly { # HttpOnly | ||||
258 | 4 | 3µs | my $self = shift; | ||
259 | 4 | 4µs | my $httponly = shift; | ||
260 | 4 | 3µs | $self->{'httponly'} = $httponly if defined $httponly; | ||
261 | 4 | 18µs | return $self->{'httponly'}; | ||
262 | } | ||||
263 | |||||
264 | 1 | 10µs | 1; | ||
265 | |||||
266 | =head1 NAME | ||||
267 | |||||
- - |