| Mojolicious documentation | Contained in the Mojolicious distribution. |
Mojo::Cookie::Request - HTTP 1.1 Request Cookie Container
use Mojo::Cookie::Request;
my $cookie = Mojo::Cookie::Request->new;
$cookie->name('foo');
$cookie->value('bar');
print "$cookie";
Mojo::Cookie::Request is a container for HTTP 1.1 request cookies as described in RFC 2965.
Mojo::Cookie::Request inherits all attributes from Mojo::Cookie.
Mojo::Cookie::Request inherits all methods from Mojo::Cookie and implements the following new ones.
parse my $cookies = $cookie->parse('$Version=1; f=b; $Path=/');
Parse cookies.
prefixmy $prefix = $cookie->prefix;
Prefix for cookies.
to_stringmy $string = $cookie->to_string;
Render cookie.
to_string_with_prefixmy $string = $cookie->to_string_with_prefix;
Render cookie with prefix.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
| Mojolicious documentation | Contained in the Mojolicious distribution. |
package Mojo::Cookie::Request; use Mojo::Base 'Mojo::Cookie'; use Mojo::Util 'unquote'; # "Lisa, would you like a donut? # No thanks. Do you have any fruit? # This has purple in it. Purple is a fruit." sub parse { my ($self, $string) = @_; # Walk tree my @cookies; my $version = 1; for my $knot ($self->_tokenize($string)) { for my $token (@{$knot}) { my ($name, $value) = @{$token}; # Value might be quoted unquote $value if $value; # Path if ($name =~ /^\$Path$/i) { $cookies[-1]->path($value) } # Version elsif ($name =~ /^\$Version$/i) { $version = $value } # Name and value else { push @cookies, Mojo::Cookie::Request->new; $cookies[-1]->name($name); unquote $value if $value; $cookies[-1]->value($value); $cookies[-1]->version($version); } } } \@cookies; } sub prefix { my $self = shift; my $version = $self->version || 1; "\$Version=$version"; } sub to_string { my $self = shift; # Render return '' unless $self->name; my $cookie = $self->name; my $value = $self->value; $cookie .= "=$value" if defined $value && length $value; if (my $path = $self->path) { $cookie .= "; \$Path=$path" } $cookie; } sub to_string_with_prefix { my $self = shift; # Render with prefix my $prefix = $self->prefix; my $cookie = $self->to_string; "$prefix; $cookie"; } 1; __END__