Jifty/Model/Session.pm

filter: Statementstmt 74.2% 26 / 35 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 7 / 14 Podpod 100% 6 / 6 totaltotal 65.0% 39 / 60 CC 2 SCAR 7.3
CC
2
Cov
68%
current_user
6.0
table
2.0
since
2.0
CRAP 2.1
« Jifty/Module/Pluggable.pm ↑ Summary Jifty/Bootstrap.pm »
1 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 Jifty::Model::Session - Jifty session tracking
7  
8 =head1 DESCRIPTION
9  
10 Every Jifty application automatically inherits this table, which
11 tracks session information for the application. Individual keys in
12 the session structure are stored as rows, making session updates take
13 constant time, and also reducing the need for locking.
14  
15 =cut
16  
17 package Jifty::Model::Session;
18 1 ▶use Jifty::DBI::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Jifty::Record schema {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
20  
21 1 column session_id => type is 'varchar(32)', is case_sensitive, is indexed;
22 1 column data_key => type is 'text', is case_sensitive;
23 1 column value => type is 'blob',
24 filters are 'Jifty::DBI::Filter::Storable';
25 1 column created => type is 'timestamp',
26 filters are 'Jifty::DBI::Filter::DateTime';
27 1 column updated => type is 'timestamp',
28 filters are 'Jifty::DBI::Filter::DateTime';
29 1 column key_type => type is 'varchar(32)', is case_sensitive, is no_placeholder;
30 1 };
31  
32 1 ▶use base qw( Jifty::Record );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 =head2 table
36  
37 Sessions are stored in the table C<_jifty_sessions>.
38  
39 =cut
40  
41 0 ▶sub table {'_jifty_sessions'}
Subroutine table: not called CC=1 SCAR=6.9
Pod documented
42  
43 =head2 since
44  
45 Sessions first started getting stored in the database in Jifty version
46 0.60428
47  
48 =cut
49  
50 0 ▶sub since { '0.60428' }
Subroutine since: not called CC=1 SCAR=6.9
51  
52 =head2 current_user
53  
54 =head2 current_user_can
55  
56 Everyone is treated as the superuser when dealing with session
57 objects. This avoids infinite recursion, as otherwise it would try to
58 look up the current user in the session object to find out who we
59 are...
60  
61 =cut
62  
63 1 my $SUPERUSER;
64 0 ▶sub current_user { return $SUPERUSER ||= Jifty->app_class('CurrentUser')->superuser }
Subroutine current_user: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$SUPERUSER ||= "Jifty"->app_class("CurrentUser")->superuser
l!l&&r!l&&!r
000
MC/DC0%0/2
$SUPERUSER ||= "Jifty"->app_class("CurrentUser")->superuser
$SUPERUSER "Jifty"->app_class("CurrentUser")->superuser
Truth table0%0/3
A ||= B
A= $SUPERUSERB= "Jifty"->app_class("CurrentUser")->superuser
ABresult
1X1
011
000
65 0 ▶sub current_user_can {return 1;}
Subroutine current_user_can: not called CC=1 SCAR=6.9
Pod documented
66  
67 =head2 new_session_id
68  
69 Returns a random new session id. This is a 32-character hex string.
70  
71 =cut
72  
73 0 ▶sub new_session_id {
Subroutine new_session_id: not called CC=1 SCAR=6.9
Pod documented
74 0 return Digest::MD5::md5_hex(
75 Digest::MD5::md5_hex( time() . {} . rand() . $$ ) );
76 }
77  
78 =head2 create
79  
80 Defaults the created and updated times to now.
81  
82 =cut
83  
84 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
85 0 my $self = shift;
86 0 my %args = (
87 session_id => $self->new_session_id,
88 key_type => "key",
89 created => DateTime->now,
90 updated => DateTime->now,
91 @_,
92 );
93  
94 0 return $self->SUPER::create(%args);
95 }
96  
97 =head2 before_set_value [VALUE]
98  
99 Updates the C<updated> column, in addition to setting the value.
100  
101 =cut
102  
103 0 ▶sub before_set_value {
Subroutine before_set_value: not called CC=1 SCAR=6.9
Pod documented
104 0 shift->set_updated( DateTime->now );
105 }
106  
107 1 1;
« Jifty/Module/Pluggable.pm ↑ Summary Jifty/Bootstrap.pm »