Net::API::REST::Cookie - Cookie Object
use Net::API::REST::Cookies; my $cookie = Net::API::REST::Cookie->new( name => 'my-cookie', domain => 'example.com', 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, request => $request_obj, # Net::API::REST::Request object );
v0.2.10
This module represents a cookie. This can be used as a standalone module, or can be managed as part of the cookie jar Net::API::REST::Cookies
The object is overloaded and will call "as_string" upon stringification.
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
Returns a string representation of the object.
my $cookie_string = $cookie->as_string; # or my $cookie_string = "$cookie"; my-cookie="sid1234567"; Domain=example.com; Path=/; Expires=Mon, 09 Jan 2020 12:17:30 GMT; Secure; HttpOnly
The returned value is cached so the next time, it simply return the cached version and not re-process it. You can reset it by calling "reset".
$cookie->comment( 'Some comment' ); my $comment = $cookie->comment;
Sets or gets the optional comment for this cookie. This was used in version 2 of cookies but has since been deprecated.
$cookie->commentURL( 'https://example.com/some/where.html' ); my $comment = $cookie->commentURL;
Sets or gets the optional comment URL for this cookie. This was used in version 2 of cookies but has since been deprecated.
$cookie->domain( 'example.com' ); my $dom = $cookie->domain;
Sets or gets the domain for this cookie.
Sets or gets the expiration date and time for this cookie.
The value provided can be one of:
For example: 1631099228
1631099228
For example: 30s (30 seconds), 5m (5 minutes), 12h (12 hours), 30D (30 days), 2M (2 months), 1Y (1 year)
30s
5m
12h
30D
2M
1Y
However, this is not sprintf, so you cannot combine them, thus you cannot do this: 5m1D
5m1D
now
Special keyword
Ultimately, a DateTime will be derived from those values, or undef will be returned and an error will be set.
undef
The DateTime object will be set with a formatter to allow a stringification that is compliant with rfc6265.
And you can use "max_age" alternatively.
See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
Sets or gets the boolean for httpOnly
httpOnly
Alias for "http_only"
Sets or gets the boolean value
Sets or gets the integer value for Max-Age
Max-Age
Alias for "max_age"
Sets or gets the cookie name.
As per the Mozilla documentation, a cookie name cannot contain any of the following charadcters:
\(\)\<\>\@\,\;\:\\\"\/\[\]\?\=\{\}
Sets or gets the path.
Sets or gets the port number.
Set the reset flag to true, which will force "as_string" to recompute the string value of the cookie.
Sets or gets the boolean value for Same-Site.
Same-Site
See rfc 6265 for more information.
Alias for "same_site".
Sets or gets the boolean value for Secure.
Secure
Sets or gets the value for this cookie.
Sets or gets the cookie version. This was used in version 2 of the cookie standard, but has since been deprecated.
Given a DateTime object, or by default will instantiate a new one, and this will set its formatter to Net::API::REST::DateTime to ensure the stringification produces a rfc6265 compliant datetime string.
Jacques Deguest <jack@deguest.jp>
CPAN ID: jdeguest
https://gitlab.com/jackdeguest/Net-API-REST
Apache2::Cookies, APR::Request::Cookie, Cookie::Baker
Copyright (c) 2018-2021 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install Net::API::REST, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::API::REST
CPAN shell
perl -MCPAN -e shell install Net::API::REST
For more information on module installation, please visit the detailed CPAN module installation guide.