Skip to content

Commit

Permalink
resolve #60 [rt.cpan.org #50576] - cookie -max-age
Browse files Browse the repository at this point in the history
argument to CGI::Cookie is now correctly set when this is passed in
the constructor. previously the value from the -expires argument was
being used, meaning it was not possible to pass *only* the -max-age
argument and have this set. this also means that the values for the
-max-age and -expires arguments can be different, should you want to
do something like that

update tests to reflect above change and increase coverage for the
-max-age constructor argument / max_age method. also update perldoc
adding missing documentation for the max_age method
  • Loading branch information
leejo committed Jun 18, 2014
1 parent 6bcc277 commit 7d46fae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Changes
@@ -1,4 +1,4 @@
4.03 ????-??-??
4.03 2014-06-30

[ REMOVED / DEPRECATIONS ]
- the -multiple option to popup_menu is now IGNORED as this did not
Expand All @@ -8,7 +8,9 @@
[ SPEC / BUG FIXES ]
- support redirects in mod_perl2, or fall back to using env variable
for up to 5 redirects, when getting the query string (RT #36312)

- CGI::Cookie now correctly supports the -max-age argument, previously
if this was passed the value of the -expires argument would be used
meaning there was no way to supply *only* this argument (RT #50576)

[ DOCUMENTATION ]
- clarify documentation regarding query_string method (RT #48370)
Expand Down
7 changes: 6 additions & 1 deletion lib/CGI/Cookie.pm
Expand Up @@ -126,7 +126,7 @@ sub new {
$self->domain( $domain ) if defined $domain;
$self->secure( $secure ) if defined $secure;
$self->expires( $expires ) if defined $expires;
$self->max_age($expires) if defined $max_age;
$self->max_age( $max_age ) if defined $max_age;
$self->httponly( $httponly ) if defined $httponly;
return $self;
}
Expand Down Expand Up @@ -337,6 +337,7 @@ See these URLs for more information:
my $c = CGI::Cookie->new(-name => 'foo',
-value => 'bar',
-expires => '+3M',
'-max-age' => '+3M',
-domain => '.capricorn.com',
-path => '/cgi-bin/database',
-secure => 1
Expand Down Expand Up @@ -503,6 +504,10 @@ Get or set the cookie's path.
Get or set the cookie's expiration time.
=item B<max_age()>
Get or set the cookie's max_age value.
=back
Expand Down
15 changes: 15 additions & 0 deletions t/cookie.t
Expand Up @@ -175,6 +175,7 @@ my @test_cookie = (
is($c->name , 'baz', 'name is correct');
is($c->value , 'qux', 'value is correct');
ok(!defined $c->expires, 'expires is not set');
ok(!defined $c->max_age, 'max_age is not set');
ok(!defined $c->domain , 'domain attributeis not set');
is($c->path, '/', 'path atribute is set to default');
ok(!defined $c->secure , 'secure attribute is set');
Expand Down Expand Up @@ -207,6 +208,7 @@ my @test_cookie = (
my $c = CGI::Cookie->new(-name => 'Jam',
-value => 'Hamster',
-expires => '+3M',
'-max-age' => '+3M',
-domain => '.pie-shop.com',
-path => '/',
-secure => 1,
Expand All @@ -222,6 +224,9 @@ my @test_cookie = (
my $expires = $c->expires;
like($c->as_string, "/$expires/", "Stringified cookie contains expires");

my $max_age = $c->max_age;
like($c->as_string, "/$max_age/", "Stringified cookie contains max_age");

my $domain = $c->domain;
like($c->as_string, "/$domain/", "Stringified cookie contains domain");

Expand All @@ -245,6 +250,8 @@ my @test_cookie = (

ok($c->as_string !~ /expires/, "Stringified cookie has no expires field");

ok($c->as_string !~ /max-age/, "Stringified cookie has no max-age field");

ok($c->as_string !~ /domain/, "Stringified cookie has no domain field");

$path = $c->path;
Expand Down Expand Up @@ -364,6 +371,14 @@ MAX_AGE: {

$cookie->max_age( '113' );
is $cookie->max_age => 13, 'max_age(num) as delta';

$cookie = CGI::Cookie->new( -name=>'a', value=>'b', '-max-age' => '+3d');
is( $cookie->max_age,3*24*60*60,'-max-age in constructor' );
ok( !$cookie->expires,' ... lack of expires' );

$cookie = CGI::Cookie->new( -name=>'a', value=>'b', '-expires' => 'now', '-max-age' => '+3d');
is( $cookie->max_age,3*24*60*60,'-max-age in constructor' );
ok( $cookie->expires,'-expires in constructor' );
}


Expand Down

0 comments on commit 7d46fae

Please sign in to comment.