Net::API::REST::Cookies - Cookie Jar and cookie management


        use Net::API::REST::Cookies;
        my $jar = Net::API::REST::Cookies->new( request => $self, debug => $self->debug ) ||
        return( $self->error( "An error occurred while trying to get the cookie jar." ) );
        if( $jar->exists( 'my-cookie' ) )
                # do something
        # get the cookie
        my $sid = $jar->get( 'my-cookie' );
        # set a new cookie
        $jar->set( 'my-cookie' => $cookie_object );
        # Remove cookie from jar
        $jar->delete( 'my-cookie' );
        return( $jar->make({
                name => 'my-cookie',
                domain => '',
                value => 'sid1234567',
                path => '/',
                expires => '+10D',
                ## or alternatively
                maxage => 864000
                ## to make it exclusively accessible by regular http request and not ajax
                http_only => 1,
                ## should it be used under ssl only?
                secure => 1,
        }) );




This is a module to handle cookies sent from the web browser, and also to create new cookie to be returned by the server to the web browser.

The reason for this module is because Apache2::Cookie does not work well in decoding cookies, and Cookie::Baker Set-Cookie timestamp format is wrong. They use Mon-09-Jan 2020 12:17:30 GMT where it should be, as per rfc 6265 Mon, 09 Jan 2020 12:17:30 GMT

Also APR::Request::Cookie and Apache2::Cookie which is a wrapper around APR::Request::Cookie return a cookie object that returns the value of the cookie upon stringification instead of the full Set-Cookie parameters. Clearly they designed it with a bias leaned toward collecting cookies from the browser.


new( hash )

This initiates the package and take the following parameters:


This is a required parameter to be sent with a value set to a Net::API::REST::Request object


Optional. If set with a positive integer, this will activate verbose debugging message

Given a cookie name, this will remove it from the cookie jar.

However, this will NOT remove it from the web browser by sending a Set-Cookie header.

It returns the value of the cookie removed.

Given a cookie name, this will check if it exists.


Retrieve all possible cookies from the http request received from the web browser.

It returns an hash reference of cookie name => cookie value

Given a cookie name, this will retrieve its value and return it.

Given a cookie name, and a cookie object, this adds it or replace the previous one if any.

This will also add the cookie to the outgoing http headers using the Set-Cookie http header.


Jacques Deguest <>

CPAN ID: jdeguest


Apache2::Cookies, APR::Request::Cookie, Cookie::Baker


Copyright (c) 2018-2019 DEGUEST Pte. Ltd.

You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.