File Coverage

blib/lib/Starch/Plugin/CookieArgs/State.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 33 37 89.1


line stmt bran cond sub pod time code
1             package Starch::Plugin::CookieArgs::State;
2 1     1   483 use 5.008001;
  1         4  
3 1     1   5 use strictures 2;
  1         6  
  1         36  
4             our $VERSION = '0.12';
5              
6 1     1   184 use Moo::Role;
  1         3  
  1         5  
7 1     1   323 use namespace::clean;
  1         2  
  1         8  
8              
9             with qw(
10             Starch::Plugin::ForState
11             );
12              
13             sub cookie_args {
14 2     2 0 19 my ($self) = @_;
15              
16 2 100       18 return $self->cookie_delete_args() if $self->is_deleted();
17 1         8 return $self->cookie_set_args();
18             }
19              
20             sub cookie_set_args {
21 6     6 0 20 my ($self) = @_;
22              
23 6         108 my $expires = $self->expires();
24              
25 6 50       127 my $args = {
26             name => $self->manager->cookie_name(),
27             value => $self->id(),
28             $expires ? (expires => "+${expires}s") : (),
29             domain => $self->manager->cookie_domain(),
30             path => $self->manager->cookie_path(),
31             secure => $self->manager->cookie_secure(),
32             httponly => $self->manager->cookie_http_only(),
33             };
34              
35             # Filter out undefined values.
36             return {
37 42         121 map { $_ => $args->{$_} }
38 6         65 grep { defined $args->{$_} }
  42         79  
39             keys( %$args )
40             };
41             }
42              
43             sub cookie_delete_args {
44 3     3 0 12 my ($self) = @_;
45              
46             return {
47 3         5 %{ $self->cookie_set_args() },
  3         7  
48             expires => '-1d',
49             };
50             }
51              
52             1;