← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 14:31:06 2016
Reported on Fri Jan 8 14:33:30 2016

Filename/usr/share/perl5/CGI/Cookie.pm
StatementsExecuted 1051 statements in 2.06ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
17111.54ms6.01msCGI::Cookie::::parseCGI::Cookie::parse
72221.43ms3.82msCGI::Cookie::::newCGI::Cookie::new
33541.23ms2.06msCGI::Cookie::::as_stringCGI::Cookie::as_string
12232406µs406µsCGI::Cookie::::valueCGI::Cookie::value
13831389µs389µsCGI::Cookie::::nameCGI::Cookie::name
13821202µs202µsCGI::Cookie::::pathCGI::Cookie::path
1711167µs6.27msCGI::Cookie::::fetchCGI::Cookie::fetch
111121µs151µsCGI::Cookie::::BEGIN@6CGI::Cookie::BEGIN@6
13621116µs116µsCGI::Cookie::::CORE:substCGI::Cookie::CORE:subst (opcode)
171187µs87µsCGI::Cookie::::get_raw_cookieCGI::Cookie::get_raw_cookie
372163µs63µsCGI::Cookie::::httponlyCGI::Cookie::httponly
331163µs63µsCGI::Cookie::::domainCGI::Cookie::domain
331161µs61µsCGI::Cookie::::expiresCGI::Cookie::expires
331158µs58µsCGI::Cookie::::max_ageCGI::Cookie::max_age
331154µs54µsCGI::Cookie::::secureCGI::Cookie::secure
11125µs42µsCGI::Cookie::::BEGIN@3CGI::Cookie::BEGIN@3
11121µs72µsCGI::Cookie::::BEGIN@11CGI::Cookie::BEGIN@11
11119µs40µsCGI::Cookie::::BEGIN@138CGI::Cookie::BEGIN@138
11116µs27µsCGI::Cookie::::BEGIN@4CGI::Cookie::BEGIN@4
11114µs52µsCGI::Cookie::::BEGIN@10CGI::Cookie::BEGIN@10
1112µs2µsCGI::Cookie::::CORE:matchCGI::Cookie::CORE:match (opcode)
0000s0sCGI::Cookie::::bakeCGI::Cookie::bake
0000s0sCGI::Cookie::::compareCGI::Cookie::compare
0000s0sCGI::Cookie::::raw_fetchCGI::Cookie::raw_fetch
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package CGI::Cookie;
2
3258µs
# spent 42µs (25+16) within CGI::Cookie::BEGIN@3 which was called: # once (25µs+16µs) by C4::Languages::getlanguage at line 3
use strict;
# spent 42µs making 1 call to CGI::Cookie::BEGIN@3 # spent 16µs making 1 call to strict::import
4238µs
# spent 27µs (16+11) within CGI::Cookie::BEGIN@4 which was called: # once (16µs+11µs) by C4::Languages::getlanguage at line 4
use warnings;
# spent 27µs making 1 call to CGI::Cookie::BEGIN@4 # spent 11µs making 1 call to warnings::import
5
62158µs
# spent 151µs (121+31) within CGI::Cookie::BEGIN@6 which was called: # once (121µs+31µs) by C4::Languages::getlanguage at line 6
use if $] >= 5.019, 'deprecate';
# spent 151µs making 1 call to CGI::Cookie::BEGIN@6 # spent 7µs making 1 call to if::import
7
8our $VERSION='4.09';
9
10290µs
# spent 52µs (14+38) within CGI::Cookie::BEGIN@10 which was called: # once (14µs+38µs) by C4::Languages::getlanguage at line 10
use CGI::Util qw(rearrange unescape escape);
# spent 52µs making 1 call to CGI::Cookie::BEGIN@10 # spent 38µs making 1 call to Exporter::import
112123µs
# spent 72µs (21+51) within CGI::Cookie::BEGIN@11 which was called: # once (21µs+51µs) by C4::Languages::getlanguage at line 11
use overload '""' => \&as_string, 'cmp' => \&compare, 'fallback' => 1;
# spent 72µs making 1 call to CGI::Cookie::BEGIN@11 # spent 51µs making 1 call to overload::import
12
13my $PERLEX = 0;
14# Turn on special checking for ActiveState's PerlEx
1512µs$PERLEX++ if defined($ENV{'GATEWAY_INTERFACE'}) && $ENV{'GATEWAY_INTERFACE'} =~ /^CGI-PerlEx/;
# spent 2µs making 1 call to CGI::Cookie::CORE:match
16
17# Turn on special checking for mod_perl
18# PerlEx::DBI tries to fool DBI by setting MOD_PERL
19my $MOD_PERL = 0;
20if (exists $ENV{MOD_PERL} && ! $PERLEX) {
21 if (exists $ENV{MOD_PERL_API_VERSION} && $ENV{MOD_PERL_API_VERSION} == 2) {
22 $MOD_PERL = 2;
23 require Apache2::RequestUtil;
24 require APR::Table;
25 } else {
26 $MOD_PERL = 1;
27 require Apache;
28 }
29}
30
31# fetch a list of cookies from the environment and
32# return as a hash. the cookies are parsed as normal
33# escaped URL data.
34
# spent 6.27ms (167µs+6.10) within CGI::Cookie::fetch which was called 17 times, avg 369µs/call: # 17 times (167µs+6.10ms) by C4::Languages::getlanguage or CGI::cookie at line 12 of (eval 1118)[CGI.pm:932], avg 369µs/call
sub fetch {
3543µs my $class = shift;
36412µs1787µs my $raw_cookie = get_raw_cookie(@_) or return;
# spent 87µs making 17 calls to CGI::Cookie::get_raw_cookie, avg 5µs/call
37420µs176.01ms return $class->parse($raw_cookie);
# spent 6.01ms making 17 calls to CGI::Cookie::parse, avg 354µs/call
38}
39
40# Fetch a list of cookies from the environment or the incoming headers and
41# return as a hash. The cookie values are not unescaped or altered in any way.
42 sub raw_fetch {
43 my $class = shift;
44 my $raw_cookie = get_raw_cookie(@_) or return;
45 my %results;
46 my($key,$value);
47
48 my @pairs = split("[;,] ?",$raw_cookie);
49 for my $pair ( @pairs ) {
50 $pair =~ s/^\s+|\s+$//g; # trim leading trailing whitespace
51 my ( $key, $value ) = split "=", $pair;
52
53 $value = defined $value ? $value : '';
54 $results{$key} = $value;
55 }
56 return wantarray ? %results : \%results;
57}
58
59
# spent 87µs within CGI::Cookie::get_raw_cookie which was called 17 times, avg 5µs/call: # 17 times (87µs+0s) by CGI::Cookie::fetch at line 36, avg 5µs/call
sub get_raw_cookie {
6042µs my $r = shift;
6141µs $r ||= eval { $MOD_PERL == 2 ?
62 Apache2::RequestUtil->request() :
63 Apache->request } if $MOD_PERL;
64
6541µs return $r->headers_in->{'Cookie'} if $r;
66
674900ns die "Run $r->subprocess_env; before calling fetch()"
68 if $MOD_PERL and !exists $ENV{REQUEST_METHOD};
69
70419µs return $ENV{HTTP_COOKIE} || $ENV{COOKIE};
71}
72
73
74
# spent 6.01ms (1.54+4.47) within CGI::Cookie::parse which was called 17 times, avg 354µs/call: # 17 times (1.54ms+4.47ms) by CGI::Cookie::fetch at line 37, avg 354µs/call
sub parse {
7543µs my ($self,$raw_cookie) = @_;
7641µs return wantarray ? () : {} unless $raw_cookie;
77
784700ns my %results;
79
80416µs my @pairs = split("[;,] ?",$raw_cookie);
8144µs for (@pairs) {
821637µs6868µs s/^\s+//;
# spent 68µs making 68 calls to CGI::Cookie::CORE:subst, avg 1µs/call
831624µs6848µs s/\s+$//;
# spent 48µs making 68 calls to CGI::Cookie::CORE:subst, avg 703ns/call
84
851621µs my($key,$value) = split("=",$_,2);
86
87 # Some foreign cookies are not in name=value format, so ignore
88 # them.
89163µs next if !defined($value);
90165µs my @values = ();
91168µs if ($value ne '') {
9216180µs136362µs @values = map unescape($_),split(/[&;]/,$value.'&dmy');
# spent 362µs making 136 calls to CGI::Util::unescape, avg 3µs/call
93164µs pop @values;
94 }
951657µs68428µs $key = unescape($key);
# spent 428µs making 68 calls to CGI::Util::unescape, avg 6µs/call
96 # A bug in Netscape can cause several cookies with same name to
97 # appear. The FIRST one in HTTP_COOKIE is the most recent version.
981658µs683.57ms $results{$key} ||= $self->new(-name=>$key,-value=>\@values);
# spent 3.57ms making 68 calls to CGI::Cookie::new, avg 52µs/call
99 }
100414µs return wantarray ? %results : \%results;
101}
102
103
# spent 3.82ms (1.43+2.39) within CGI::Cookie::new which was called 72 times, avg 53µs/call: # 68 times (1.31ms+2.25ms) by CGI::Cookie::parse at line 98, avg 52µs/call # 4 times (116µs+140µs) by CGI::cookie at line 33 of (eval 1118)[CGI.pm:932], avg 64µs/call
sub new {
1041713µs my ( $class, @params ) = @_;
105174µs $class = ref( $class ) || $class;
106 # Ignore mod_perl request object--compatibility with Apache::Cookie.
107 shift if ref $params[0]
108173µs && eval { $params[0]->isa('Apache::Request::Req') || $params[0]->isa('Apache') };
10917473µs721.68ms my ( $name, $value, $path, $domain, $secure, $expires, $max_age, $httponly )
# spent 1.68ms making 72 calls to CGI::Util::rearrange, avg 23µs/call
110 = rearrange(
111 [
112 'NAME', [ 'VALUE', 'VALUES' ],
113 'PATH', 'DOMAIN',
114 'SECURE', 'EXPIRES',
115 'MAX-AGE','HTTPONLY'
116 ],
117 @params
118 );
1191740µs return undef unless defined $name and defined $value;
1201736µs my $self = {};
1211744µs bless $self, $class;
1221771µs72266µs $self->name( $name );
# spent 266µs making 72 calls to CGI::Cookie::name, avg 4µs/call
1231733µs72308µs $self->value( $value );
# spent 308µs making 72 calls to CGI::Cookie::value, avg 4µs/call
124177µs $path ||= "/";
1251726µs72130µs $self->path( $path ) if defined $path;
# spent 130µs making 72 calls to CGI::Cookie::path, avg 2µs/call
126174µs $self->domain( $domain ) if defined $domain;
127173µs $self->secure( $secure ) if defined $secure;
128172µs $self->expires( $expires ) if defined $expires;
129173µs $self->max_age( $max_age ) if defined $max_age;
130174µs410µs $self->httponly( $httponly ) if defined $httponly;
# spent 10µs making 4 calls to CGI::Cookie::httponly, avg 2µs/call
1311740µs return $self;
132}
133
134
# spent 2.06ms (1.23+830µs) within CGI::Cookie::as_string which was called 33 times, avg 62µs/call: # 17 times (668µs+447µs) by C4::Languages::getlanguage or CGI::cookie at line 17 of (eval 1118)[CGI.pm:932], avg 66µs/call # 4 times (204µs+137µs) by C4::Auth::checkauth at line 1172 of C4/Auth.pm, avg 85µs/call # 4 times (169µs+132µs) by C4::Output::output_with_http_headers at line 275 of C4/Output.pm, avg 75µs/call # 4 times (96µs+57µs) by C4::Output::output_with_http_headers or CGI::header at line 75 of (eval 1139)[CGI.pm:932], avg 38µs/call # 4 times (94µs+58µs) by C4::Output::output_with_http_headers or CGI::header at line 17 of (eval 1139)[CGI.pm:932], avg 38µs/call
sub as_string {
13583µs my $self = shift;
136811µs3384µs return "" unless $self->name;
# spent 84µs making 33 calls to CGI::Cookie::name, avg 3µs/call
137
138262µs
# spent 40µs (19+21) within CGI::Cookie::BEGIN@138 which was called: # once (19µs+21µs) by C4::Languages::getlanguage at line 138
no warnings; # some things may be undefined, that's OK.
# spent 40µs making 1 call to CGI::Cookie::BEGIN@138 # spent 22µs making 1 call to warnings::unimport
139
140882µs66252µs my $name = escape( $self->name );
# spent 212µs making 33 calls to CGI::Util::escape, avg 6µs/call # spent 39µs making 33 calls to CGI::Cookie::name, avg 1µs/call
1411663µs66134µs my $value = join "&", map { escape($_) } $self->value;
# spent 72µs making 33 calls to CGI::Cookie::value, avg 2µs/call # spent 61µs making 33 calls to CGI::Util::escape, avg 2µs/call
142815µs my @cookie = ( "$name=$value" );
143
144812µs3363µs push @cookie,"domain=".$self->domain if $self->domain;
# spent 63µs making 33 calls to CGI::Cookie::domain, avg 2µs/call
145822µs6672µs push @cookie,"path=".$self->path if $self->path;
# spent 72µs making 66 calls to CGI::Cookie::path, avg 1µs/call
146814µs3361µs push @cookie,"expires=".$self->expires if $self->expires;
# spent 61µs making 33 calls to CGI::Cookie::expires, avg 2µs/call
147812µs3358µs push @cookie,"max-age=".$self->max_age if $self->max_age;
# spent 58µs making 33 calls to CGI::Cookie::max_age, avg 2µs/call
148811µs3354µs push @cookie,"secure" if $self->secure;
# spent 54µs making 33 calls to CGI::Cookie::secure, avg 2µs/call
149811µs3353µs push @cookie,"HttpOnly" if $self->httponly;
# spent 53µs making 33 calls to CGI::Cookie::httponly, avg 2µs/call
150
151828µs return join "; ", @cookie;
152}
153
154sub compare {
155 my ( $self, $value ) = @_;
156 return "$self" cmp $value;
157}
158
159sub bake {
160 my ($self, $r) = @_;
161
162 $r ||= eval {
163 $MOD_PERL == 2
164 ? Apache2::RequestUtil->request()
165 : Apache->request
166 } if $MOD_PERL;
167 if ($r) {
168 $r->headers_out->add('Set-Cookie' => $self->as_string);
169 } else {
170 require CGI;
171 print CGI::header(-cookie => $self);
172 }
173
174}
175
176# accessors
177
# spent 389µs within CGI::Cookie::name which was called 138 times, avg 3µs/call: # 72 times (266µs+0s) by CGI::Cookie::new at line 122, avg 4µs/call # 33 times (84µs+0s) by CGI::Cookie::as_string at line 136, avg 3µs/call # 33 times (39µs+0s) by CGI::Cookie::as_string at line 140, avg 1µs/call
sub name {
1783326µs my ( $self, $name ) = @_;
1793327µs $self->{'name'} = $name if defined $name;
1803388µs return $self->{'name'};
181}
182
183
# spent 406µs within CGI::Cookie::value which was called 122 times, avg 3µs/call: # 72 times (308µs+0s) by CGI::Cookie::new at line 123, avg 4µs/call # 33 times (72µs+0s) by CGI::Cookie::as_string at line 141, avg 2µs/call # 17 times (26µs+0s) by C4::Languages::getlanguage or CGI::cookie at line 18 of (eval 1118)[CGI.pm:932], avg 2µs/call
sub value {
1842913µs my ( $self, $value ) = @_;
1852914µs if ( defined $value ) {
186 my @values
1871721µs = ref $value eq 'ARRAY' ? @$value
188 : ref $value eq 'HASH' ? %$value
189 : ( $value );
1901723µs $self->{'value'} = [@values];
191 }
1922973µs return wantarray ? @{ $self->{'value'} } : $self->{'value'}->[0];
193}
194
195
# spent 63µs within CGI::Cookie::domain which was called 33 times, avg 2µs/call: # 33 times (63µs+0s) by CGI::Cookie::as_string at line 144, avg 2µs/call
sub domain {
19682µs my ( $self, $domain ) = @_;
19782µs $self->{'domain'} = lc $domain if defined $domain;
198817µs return $self->{'domain'};
199}
200
201
# spent 54µs within CGI::Cookie::secure which was called 33 times, avg 2µs/call: # 33 times (54µs+0s) by CGI::Cookie::as_string at line 148, avg 2µs/call
sub secure {
20283µs my ( $self, $secure ) = @_;
20382µs $self->{'secure'} = $secure if defined $secure;
204814µs return $self->{'secure'};
205}
206
207
# spent 61µs within CGI::Cookie::expires which was called 33 times, avg 2µs/call: # 33 times (61µs+0s) by CGI::Cookie::as_string at line 146, avg 2µs/call
sub expires {
20882µs my ( $self, $expires ) = @_;
20983µs $self->{'expires'} = CGI::Util::expires($expires,'cookie') if defined $expires;
210816µs return $self->{'expires'};
211}
212
213
# spent 58µs within CGI::Cookie::max_age which was called 33 times, avg 2µs/call: # 33 times (58µs+0s) by CGI::Cookie::as_string at line 147, avg 2µs/call
sub max_age {
21482µs my ( $self, $max_age ) = @_;
21583µs $self->{'max-age'} = CGI::Util::expire_calc($max_age)-time() if defined $max_age;
216815µs return $self->{'max-age'};
217}
218
219
# spent 202µs within CGI::Cookie::path which was called 138 times, avg 1µs/call: # 72 times (130µs+0s) by CGI::Cookie::new at line 125, avg 2µs/call # 66 times (72µs+0s) by CGI::Cookie::as_string at line 145, avg 1µs/call
sub path {
220339µs my ( $self, $path ) = @_;
2213311µs $self->{'path'} = $path if defined $path;
2223359µs return $self->{'path'};
223}
224
225
226
# spent 63µs within CGI::Cookie::httponly which was called 37 times, avg 2µs/call: # 33 times (53µs+0s) by CGI::Cookie::as_string at line 149, avg 2µs/call # 4 times (10µs+0s) by CGI::Cookie::new at line 130, avg 2µs/call
sub httponly { # HttpOnly
22793µs my ( $self, $httponly ) = @_;
22892µs $self->{'httponly'} = $httponly if defined $httponly;
229922µs return $self->{'httponly'};
230}
231
2321;
233
234=head1 NAME
235
236CGI::Cookie - Interface to HTTP Cookies
237
238=head1 SYNOPSIS
239
240 use CGI qw/:standard/;
241 use CGI::Cookie;
242
243 # Create new cookies and send them
244 $cookie1 = CGI::Cookie->new(-name=>'ID',-value=>123456);
245 $cookie2 = CGI::Cookie->new(-name=>'preferences',
246 -value=>{ font => Helvetica,
247 size => 12 }
248 );
249 print header(-cookie=>[$cookie1,$cookie2]);
250
251 # fetch existing cookies
252 %cookies = CGI::Cookie->fetch;
253 $id = $cookies{'ID'}->value;
254
255 # create cookies returned from an external source
256 %cookies = CGI::Cookie->parse($ENV{COOKIE});
257
258=head1 DESCRIPTION
259
260CGI::Cookie is an interface to HTTP/1.1 cookies, a mechanism
261that allows Web servers to store persistent information on
262the browser's side of the connection. Although CGI::Cookie is
263intended to be used in conjunction with CGI.pm (and is in fact used by
264it internally), you can use this module independently.
265
266For full information on cookies see
267
268 https://tools.ietf.org/html/rfc6265
269
270=head1 USING CGI::Cookie
271
272CGI::Cookie is object oriented. Each cookie object has a name and a
273value. The name is any scalar value. The value is any scalar or
274array value (associative arrays are also allowed). Cookies also have
275several optional attributes, including:
276
277=over 4
278
279=item B<1. expiration date>
280
281The expiration date tells the browser how long to hang on to the
282cookie. If the cookie specifies an expiration date in the future, the
283browser will store the cookie information in a disk file and return it
284to the server every time the user reconnects (until the expiration
285date is reached). If the cookie species an expiration date in the
286past, the browser will remove the cookie from the disk file. If the
287expiration date is not specified, the cookie will persist only until
288the user quits the browser.
289
290=item B<2. domain>
291
292This is a partial or complete domain name for which the cookie is
293valid. The browser will return the cookie to any host that matches
294the partial domain name. For example, if you specify a domain name
295of ".capricorn.com", then the browser will return the cookie to
296Web servers running on any of the machines "www.capricorn.com",
297"ftp.capricorn.com", "feckless.capricorn.com", etc. Domain names
298must contain at least two periods to prevent attempts to match
299on top level domains like ".edu". If no domain is specified, then
300the browser will only return the cookie to servers on the host the
301cookie originated from.
302
303=item B<3. path>
304
305If you provide a cookie path attribute, the browser will check it
306against your script's URL before returning the cookie. For example,
307if you specify the path "/cgi-bin", then the cookie will be returned
308to each of the scripts "/cgi-bin/tally.pl", "/cgi-bin/order.pl", and
309"/cgi-bin/customer_service/complain.pl", but not to the script
310"/cgi-private/site_admin.pl". By default, the path is set to "/", so
311that all scripts at your site will receive the cookie.
312
313=item B<4. secure flag>
314
315If the "secure" attribute is set, the cookie will only be sent to your
316script if the CGI request is occurring on a secure channel, such as SSL.
317
318=item B<5. httponly flag>
319
320If the "httponly" attribute is set, the cookie will only be accessible
321through HTTP Requests. This cookie will be inaccessible via JavaScript
322(to prevent XSS attacks).
323
324This feature is supported by nearly all modern browsers.
325
326See these URLs for more information:
327
328 http://msdn.microsoft.com/en-us/library/ms533046.aspx
329 http://www.browserscope.org/?category=security&v=top
330
331=back
332
333=head2 Creating New Cookies
334
335 my $c = CGI::Cookie->new(-name => 'foo',
336 -value => 'bar',
337 -expires => '+3M',
338 '-max-age' => '+3M',
339 -domain => '.capricorn.com',
340 -path => '/cgi-bin/database',
341 -secure => 1
342 );
343
344Create cookies from scratch with the B<new> method. The B<-name> and
345B<-value> parameters are required. The name must be a scalar value.
346The value can be a scalar, an array reference, or a hash reference.
347(At some point in the future cookies will support one of the Perl
348object serialization protocols for full generality).
349
350B<-expires> accepts any of the relative or absolute date formats
351recognized by CGI.pm, for example "+3M" for three months in the
352future. See CGI.pm's documentation for details.
353
354B<-max-age> accepts the same data formats as B<< -expires >>, but sets a
355relative value instead of an absolute like B<< -expires >>. This is intended to be
356more secure since a clock could be changed to fake an absolute time. In
357practice, as of 2011, C<< -max-age >> still does not enjoy the widespread support
358that C<< -expires >> has. You can set both, and browsers that support
359C<< -max-age >> should ignore the C<< Expires >> header. The drawback
360to this approach is the bit of bandwidth for sending an extra header on each cookie.
361
362B<-domain> points to a domain name or to a fully qualified host name.
363If not specified, the cookie will be returned only to the Web server
364that created it.
365
366B<-path> points to a partial URL on the current server. The cookie
367will be returned to all URLs beginning with the specified path. If
368not specified, it defaults to '/', which returns the cookie to all
369pages at your site.
370
371B<-secure> if set to a true value instructs the browser to return the
372cookie only when a cryptographic protocol is in use.
373
374B<-httponly> if set to a true value, the cookie will not be accessible
375via JavaScript.
376
377For compatibility with Apache::Cookie, you may optionally pass in
378a mod_perl request object as the first argument to C<new()>. It will
379simply be ignored:
380
381 my $c = CGI::Cookie->new($r,
382 -name => 'foo',
383 -value => ['bar','baz']);
384
385=head2 Sending the Cookie to the Browser
386
387The simplest way to send a cookie to the browser is by calling the bake()
388method:
389
390 $c->bake;
391
392This will print the Set-Cookie HTTP header to STDOUT using CGI.pm. CGI.pm
393will be loaded for this purpose if it is not already. Otherwise CGI.pm is not
394required or used by this module.
395
396Under mod_perl, pass in an Apache request object:
397
398 $c->bake($r);
399
400If you want to set the cookie yourself, Within a CGI script you can send
401a cookie to the browser by creating one or more Set-Cookie: fields in the
402HTTP header. Here is a typical sequence:
403
404 my $c = CGI::Cookie->new(-name => 'foo',
405 -value => ['bar','baz'],
406 -expires => '+3M');
407
408 print "Set-Cookie: $c\n";
409 print "Content-Type: text/html\n\n";
410
411To send more than one cookie, create several Set-Cookie: fields.
412
413If you are using CGI.pm, you send cookies by providing a -cookie
414argument to the header() method:
415
416 print header(-cookie=>$c);
417
418Mod_perl users can set cookies using the request object's header_out()
419method:
420
421 $r->headers_out->set('Set-Cookie' => $c);
422
423Internally, Cookie overloads the "" operator to call its as_string()
424method when incorporated into the HTTP header. as_string() turns the
425Cookie's internal representation into an RFC-compliant text
426representation. You may call as_string() yourself if you prefer:
427
428 print "Set-Cookie: ",$c->as_string,"\n";
429
430=head2 Recovering Previous Cookies
431
432 %cookies = CGI::Cookie->fetch;
433
434B<fetch> returns an associative array consisting of all cookies
435returned by the browser. The keys of the array are the cookie names. You
436can iterate through the cookies this way:
437
438 %cookies = CGI::Cookie->fetch;
439 for (keys %cookies) {
440 do_something($cookies{$_});
441 }
442
443In a scalar context, fetch() returns a hash reference, which may be more
444efficient if you are manipulating multiple cookies.
445
446CGI.pm uses the URL escaping methods to save and restore reserved characters
447in its cookies. If you are trying to retrieve a cookie set by a foreign server,
448this escaping method may trip you up. Use raw_fetch() instead, which has the
449same semantics as fetch(), but performs no unescaping.
450
451You may also retrieve cookies that were stored in some external
452form using the parse() class method:
453
454 $COOKIES = `cat /usr/tmp/Cookie_stash`;
455 %cookies = CGI::Cookie->parse($COOKIES);
456
457If you are in a mod_perl environment, you can save some overhead by
458passing the request object to fetch() like this:
459
460 CGI::Cookie->fetch($r);
461
462If the value passed to parse() is undefined, an empty array will returned in list
463context, and an empty hashref will be returned in scalar context.
464
465=head2 Manipulating Cookies
466
467Cookie objects have a series of accessor methods to get and set cookie
468attributes. Each accessor has a similar syntax. Called without
469arguments, the accessor returns the current value of the attribute.
470Called with an argument, the accessor changes the attribute and
471returns its new value.
472
473=over 4
474
475=item B<name()>
476
477Get or set the cookie's name. Example:
478
479 $name = $c->name;
480 $new_name = $c->name('fred');
481
482=item B<value()>
483
484Get or set the cookie's value. Example:
485
486 $value = $c->value;
487 @new_value = $c->value(['a','b','c','d']);
488
489B<value()> is context sensitive. In a list context it will return
490the current value of the cookie as an array. In a scalar context it
491will return the B<first> value of a multivalued cookie.
492
493=item B<domain()>
494
495Get or set the cookie's domain.
496
497=item B<path()>
498
499Get or set the cookie's path.
500
501=item B<expires()>
502
503Get or set the cookie's expiration time.
504
505=item B<max_age()>
506
507Get or set the cookie's max_age value.
508
509=back
510
511
512=head1 AUTHOR INFORMATION
513
514The CGI.pm distribution is copyright 1995-2007, Lincoln D. Stein. It is
515distributed under GPL and the Artistic License 2.0. It is currently
516maintained by Lee Johnson with help from many contributors.
517
518Address bug reports and comments to: https://github.com/leejo/CGI.pm/issues
519
520The original bug tracker can be found at: https://rt.cpan.org/Public/Dist/Display.html?Queue=CGI.pm
521
522When sending bug reports, please provide the version of CGI.pm, the version of
523Perl, the name and version of your Web server, and the name and version of the
524operating system you are using. If the problem is even remotely browser
525dependent, please provide information about the affected browsers as well.
526
527=head1 BUGS
528
529This section intentionally left blank.
530
531=head1 SEE ALSO
532
533L<CGI::Carp>, L<CGI>
534
535L<RFC 2109|http://www.ietf.org/rfc/rfc2109.txt>, L<RFC 2695|http://www.ietf.org/rfc/rfc2965.txt>
536
537=cut
 
# spent 2µs within CGI::Cookie::CORE:match which was called: # once (2µs+0s) by C4::Languages::getlanguage at line 15
sub CGI::Cookie::CORE:match; # opcode
# spent 116µs within CGI::Cookie::CORE:subst which was called 136 times, avg 851ns/call: # 68 times (68µs+0s) by CGI::Cookie::parse at line 82, avg 1µs/call # 68 times (48µs+0s) by CGI::Cookie::parse at line 83, avg 703ns/call
sub CGI::Cookie::CORE:subst; # opcode