Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

Released Cookie::Baker to CPAN

I released Cookie::Baker that provides HTTP cookie generator and parser

http://search.cpan.org/~kazeburo/Cookie-Baker/
https://metacpan.org/release/Cookie-Baker

### synopsis

use Cookie::Baker;

$headers->push_header('Set-Cookie', bake_cookie('foo','val'));

my $cookie = bake_cookie('foo', {
    val => 'val',
    path => "test",
    domain => '.example.com',
    expires => '+24h'
});

my $cookies_hashref = crush_cookie($headers->header('Cookie'));

bake_cookie's expires accepts some formats like this.

expires => time + 24 * 60 * 60 # epoch time
expires => 'Wed, 03-Nov-2010 20:54:16 GMT' 
expires => '+30s' # 30 seconds from now
expires => '+10m' # ten minutes from now
expires => '+1h'  # one hour from now 
expires => '-1d'  # yesterday (i.e. "ASAP!")
expires => '+3M'  # in three months
expires => '+10y' # in ten years time
expires => 'now'  #immediately

I know that cpan has already may cookie related modules. But dead simple cookie generator and parser module to use Plack::Middlewares and Web Applications isn't there.