GX/Session/Tracker/Cookie.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 97.8% 45 / 46 CC 2 SCAR 2.0
CC
2
Cov
97%
get_id
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« GX/Session/Store.pm ↑ Summary GX/Action.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Session/Tracker/Cookie.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Session::Tracker::Cookie;
7  
8 2 ▶use GX::HTTP::Response::Cookie;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # ----------------------------------------------------------------------------------------------------------------------
12 # Class setup
13 # ----------------------------------------------------------------------------------------------------------------------
14  
15 2 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 extends 'GX::Session::Tracker';
18  
19 2 has 'cookie_attributes' => (
20 isa => 'Hash',
21 initialize => 1,
22 accessors => {
23 'cookie_attributes' => { type => 'get_list' },
24 '_get_cookie_attributes' => { type => 'get_reference' }
25 }
26 );
27  
28 2 build;
29  
30  
31 # ----------------------------------------------------------------------------------------------------------------------
32 # Public methods
33 # ----------------------------------------------------------------------------------------------------------------------
34  
35 1 ▶sub get_id {
Subroutine get_id: called CC=2 SCAR=7.0
Pod documented
36  
37 1 my $self = shift;
38 1 my $context = shift;
39  
40 1 my $cookie = $context->request->cookies->get( $self->_get_cookie_attributes->{'name'} );
41  
42 1 ▶ return $cookie ? $cookie->value : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cookie ? : 1 0 1
43  
44 }
45  
46 2 ▶sub set_id {
Subroutine set_id: called CC=1 SCAR=0.0
Pod documented
47  
48 2 my $self = shift;
49 2 my $context = shift;
50 2 my $id = shift;
51  
52 2 my $cookie = $self->_create_session_cookie( value => $id );
53  
54 2 $context->response->cookies->set( $cookie );
55  
56 2 return 1;
57  
58 }
59  
60 1 ▶sub unset_id {
Subroutine unset_id: called CC=1 SCAR=0.0
Pod documented
61  
62 1 my $self = shift;
63 1 my $context = shift;
64  
65 1 my $cookie = $self->_create_session_cookie(
66 'value' => '',
67 'max_age' => 0
68 );
69  
70 1 $context->response->cookies->set( $cookie );
71  
72 1 return 1;
73  
74 }
75  
76  
77 # ----------------------------------------------------------------------------------------------------------------------
78 # Private methods
79 # ----------------------------------------------------------------------------------------------------------------------
80  
81 3 ▶sub _create_session_cookie {
Subroutine _create_session_cookie: called CC=1 SCAR=0.0
82  
83 3 my $self = shift;
84  
85 3 return GX::HTTP::Response::Cookie->new( $self->cookie_attributes, @_ );
86  
87 }
88  
89 4 ▶sub _default_cookie_attributes {
Subroutine _default_cookie_attributes: called CC=1 SCAR=0.0
90  
91 return {
92 4 'name' => 'SESSION_ID',
93 'path' => '/',
94 'secure' => 0,
95 'http_only' => 1
96 };
97  
98 }
99  
100  
101 # ----------------------------------------------------------------------------------------------------------------------
102 # Internal methods
103 # ----------------------------------------------------------------------------------------------------------------------
104  
105 4 ▶sub __finalize {
Subroutine __finalize: called CC=1 SCAR=0.0
106  
107 4 my $self = shift;
108  
109 4 my $cookie_attributes = $self->_get_cookie_attributes;
110  
111 4 %$cookie_attributes = ( %{$self->_default_cookie_attributes}, %$cookie_attributes );
112  
113 4 return;
114  
115 }
116  
117  
118 2 1;
119  
120 __END__
« GX/Session/Store.pm ↑ Summary GX/Action.pm »