| 1 | package Mojo::Cookie::Request; | ||||||||||||||||||||
| 2 | 29 | ▶ | use Mojo::Base 'Mojo::Cookie'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 29 | ▶ | use Mojo::Util qw(quote split_header); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 58 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 7 | 58 | my ($self, $str) = @_; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 58 | my @cookies; | |||||||||||||||||||
| 10 | 58 | ▶ | my @pairs = map {@$_} @{split_header $str // ''}; | ||||||||||||||||||
|
Condition100%2/2
$str // ""
MC/DC100%1/1
$str // ""
$str
Truth table100%2/2
A
A= $str
| |||||||||||||||||||||
| 11 | 58 | ▶ | while (my ($name, $value) = splice @pairs, 0, 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 12 | 72 | ▶ | next if $name =~ /^\$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 13 | 49 | ▶ | push @cookies, $self->new(name => $name, value => $value // ''); | ||||||||||||||||||
|
Condition50%1/2
$value // ""
MC/DC0%0/1
$value // ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 58 | return \@cookies; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 31 | ▶ | sub to_string { | ||||||||||||||||||
|
Subroutine
to_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 20 | 31 | my $self = shift; | |||||||||||||||||||
| 21 | 31 | ▶ | return '' unless length(my $name = $self->name // ''); | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->name // ""
MC/DC100%1/1
$self->name // ""
$self->name
Truth table100%2/2
A
A= $self->name
| |||||||||||||||||||||
| 22 | 30 | ▶ | my $value = $self->value // ''; | ||||||||||||||||||
|
Condition100%2/2
$self->value // ""
MC/DC100%1/1
$self->value // ""
$self->value
Truth table100%2/2
A
A= $self->value
| |||||||||||||||||||||
| 23 | 30 | ▶ | return join '=', $name, $value =~ /[,;" ]/ ? quote $value : $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 29 | 1; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =encoding utf8 | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 NAME | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | Mojo::Cookie::Request - HTTP request cookie | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | use Mojo::Cookie::Request; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | my $cookie = Mojo::Cookie::Request->new; | ||||||||||||||||||||
| 39 | $cookie->name('foo'); | ||||||||||||||||||||
| 40 | $cookie->value('bar'); | ||||||||||||||||||||
| 41 | say "$cookie"; | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | L<Mojo::Cookie::Request> is a container for HTTP request cookies, based on L<RFC | ||||||||||||||||||||
| 46 | 6265|https://tools.ietf.org/html/rfc6265>. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | L<Mojo::Cookie::Request> inherits all attributes from L<Mojo::Cookie>. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head1 METHODS | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | L<Mojo::Cookie::Request> inherits all methods from L<Mojo::Cookie> and implements the following new ones. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head2 parse | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | my $cookies = Mojo::Cookie::Request->parse('f=b; g=a'); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Parse cookies. | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head2 to_string | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | my $str = $cookie->to_string; | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Render cookie. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 SEE ALSO | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||