# wish, but if you redistribute a modified version, please attach a note
# listing the modifications you have made.
-$CGI::Cookie::VERSION='1.18';
+$CGI::Cookie::VERSION='1.21';
use CGI::Util qw(rearrange unescape escape);
use overload '""' => \&as_string,
my(@pairs) = split("; ?",$raw_cookie);
foreach (@pairs) {
s/\s*(.*?)\s*/$1/;
- my($key,$value) = split("=");
+ my($key,$value) = split("=",$_,2);
# Some foreign cookies are not in name=value format, so ignore
# them.
next if !defined($value);
my @values = ();
if ($value ne '') {
- @values = map CGI::unescape($_),split(/[&;]/,$value.'&dmy');
+ @values = map unescape($_),split(/[&;]/,$value.'&dmy');
pop @values;
}
$key = unescape($key);
$self->domain($domain) if defined $domain;
$self->secure($secure) if defined $secure;
$self->expires($expires) if defined $expires;
+# $self->max_age($expires) if defined $expires;
return $self;
}
my $self = shift;
return "" unless $self->name;
- my(@constant_values,$domain,$path,$expires,$secure);
+ my(@constant_values,$domain,$path,$expires,$max_age,$secure);
- push(@constant_values,"domain=$domain") if $domain = $self->domain;
- push(@constant_values,"path=$path") if $path = $self->path;
+ push(@constant_values,"domain=$domain") if $domain = $self->domain;
+ push(@constant_values,"path=$path") if $path = $self->path;
push(@constant_values,"expires=$expires") if $expires = $self->expires;
+ push(@constant_values,"max-age=$max_age") if $max_age = $self->max_age;
push(@constant_values,"secure") if $secure = $self->secure;
my($key) = escape($self->name);
sub value {
my $self = shift;
my $value = shift;
- $self->{'value'} = $value if defined $value;
+ if (defined $value) {
+ my @values;
+ if (ref($value)) {
+ if (ref($value) eq 'ARRAY') {
+ @values = @$value;
+ } elsif (ref($value) eq 'HASH') {
+ @values = %$value;
+ }
+ } else {
+ @values = ($value);
+ }
+ $self->{'value'} = [@values];
+ }
return wantarray ? @{$self->{'value'}} : $self->{'value'}->[0]
}
return $self->{'expires'};
}
+sub max_age {
+ my $self = shift;
+ my $expires = shift;
+ $self->{'max-age'} = CGI::Util::expire_calc($expires)-time if defined $expires;
+ return $self->{'max-age'};
+}
+
sub path {
my $self = shift;
my $path = shift;
-value => 'bar',
-expires => '+3M',
-domain => '.capricorn.com',
- -path => '/cgi-bin/database'
+ -path => '/cgi-bin/database',
-secure => 1
);