NAME
Net::API::REST::Cookie - Cookie Object
SYNOPSIS
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
);
VERSION
v0.2.10
DESCRIPTION
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.
METHODS
new( hash )
This initiates the package and take the following parameters:
- request
-
This is a required parameter to be sent with a value set to a Net::API::REST::Request object
- debug
-
Optional. If set with a positive integer, this will activate verbose debugging message
- name
- value
- comment
- commentURL
- domain
- expires
- http_only
- max_age
- path
- port
- same_site
- secure
- version
as_string
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".
comment
$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.
commentURL
$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.
domain
$cookie->domain( 'example.com' );
my $dom = $cookie->domain;
Sets or gets the domain for this cookie.
expires
Sets or gets the expiration date and time for this cookie.
The value provided can be one of:
- unix timestamp.
-
For example:
1631099228
- variable time.
-
For example:
30s
(30 seconds),5m
(5 minutes),12h
(12 hours),30D
(30 days),2M
(2 months),1Y
(1 year)However, this is not sprintf, so you cannot combine them, thus you cannot do this:
5m1D
now
-
Special keyword
- In last resort, the value provided will be used as-is
Ultimately, a DateTime will be derived from those values, or undef
will be returned and an error will be set.
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
http_only
Sets or gets the boolean for httpOnly
httponly
Alias for "http_only"
is_tainted
Sets or gets the boolean value
max_age
Sets or gets the integer value for Max-Age
maxage
Alias for "max_age"
name
Sets or gets the cookie name.
As per the Mozilla documentation, a cookie name cannot contain any of the following charadcters:
\(\)\<\>\@\,\;\:\\\"\/\[\]\?\=\{\}
path
Sets or gets the path.
port
Sets or gets the port number.
reset
Set the reset flag to true, which will force "as_string" to recompute the string value of the cookie.
same_site
Sets or gets the boolean value for Same-Site
.
See rfc 6265 for more information.
samesite
Alias for "same_site".
secure
Sets or gets the boolean value for Secure
.
value
Sets or gets the value for this cookie.
version
Sets or gets the cookie version. This was used in version 2 of the cookie standard, but has since been deprecated.
_header_datetime
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.
AUTHOR
Jacques Deguest <jack@deguest.jp>
CPAN ID: jdeguest
https://gitlab.com/jackdeguest/Net-API-REST
SEE ALSO
Apache2::Cookies, APR::Request::Cookie, Cookie::Baker
COPYRIGHT & LICENSE
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.