line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Session::Store::DBIC::Delegate; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw/Class::Accessor::Fast/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
813
|
|
6
|
1
|
|
|
1
|
|
3040
|
use Carp qw/carp/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
7
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw/blessed/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
540
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/model id_field data_field _session_row _flash_row/); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Catalyst::Plugin::Session::Store::DBIC::Delegate - Delegates between the session and flash rows |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This class delegates between two rows in your sessions table for a |
18
|
|
|
|
|
|
|
given session (session and flash). This is done for compatibility |
19
|
|
|
|
|
|
|
with L<Catalyst::Plugin::Session::Store::DBI>. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 session |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Return the session row for this delegate. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub session { |
30
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $row = $self->_session_row; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
unless ($row) { |
35
|
0
|
|
|
|
|
|
$row = $self->_load_row($key); |
36
|
0
|
|
|
|
|
|
$self->_session_row($row); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $row; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 flash |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Return the flash row for this delegate. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub flash { |
49
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $row = $self->_flash_row; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
unless ($row) { |
54
|
0
|
|
|
|
|
|
$row = $self->_load_row($key); |
55
|
0
|
|
|
|
|
|
$self->_flash_row($row); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $row; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 _load_row |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Load the specified session or flash row from the database. This is a |
64
|
|
|
|
|
|
|
wrapper around L<DBIx::Class::ResultSet/find_or_create> to add support |
65
|
|
|
|
|
|
|
for transactions. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _load_row { |
70
|
0
|
|
|
0
|
|
|
my ($self, $key) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $load_sub = sub { |
73
|
0
|
|
|
0
|
|
|
return $self->model->find_or_create({ $self->id_field => $key }) |
74
|
0
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $row; |
77
|
0
|
0
|
0
|
|
|
|
if (blessed $self->model and $self->model->can('result_source')) { |
78
|
0
|
|
|
|
|
|
$row = $self->model->result_source->schema->txn_do($load_sub); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
|
|
|
|
|
|
# Fallback for DBIx::Class::DB |
82
|
0
|
|
|
|
|
|
$row = $load_sub->(); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $row; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 expires |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Return the expires row for this delegate. As with |
91
|
|
|
|
|
|
|
L<Catalyst::Plugin::Session::Store::DBI>, this maps to the L</session> |
92
|
|
|
|
|
|
|
row. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub expires { |
97
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$key =~ s/^expires/session/; |
100
|
0
|
|
|
|
|
|
$self->session($key); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 flush |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Update the session and flash data in the backend store. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub flush { |
110
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
for (qw/_session_row _flash_row/) { |
113
|
0
|
|
|
|
|
|
my $row = $self->$_; |
114
|
0
|
0
|
|
|
|
|
next unless $row; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Check the size if available to avoid silent trucation on e.g. MySQL |
117
|
0
|
|
|
|
|
|
my $data_field = $self->data_field; |
118
|
0
|
0
|
|
|
|
|
if (my $size = $row->result_source->column_info($data_field)->{size}) { |
119
|
0
|
|
|
|
|
|
my $total_size = length($row->$data_field); |
120
|
0
|
0
|
|
|
|
|
carp "This session requires $total_size bytes of storage, but your database column '$data_field' can only store $size bytes. Storing this session may not be reliable; increase the size of your data field" |
121
|
|
|
|
|
|
|
if $total_size > $size; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
$row->update if $row->in_storage; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$self->_clear_instance_data; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 _clear_instance_data |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Remove any references held by the delegate. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _clear_instance_data { |
137
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$self->id_field(undef); |
140
|
0
|
|
|
|
|
|
$self->model(undef); |
141
|
0
|
|
|
|
|
|
$self->_session_row(undef); |
142
|
0
|
|
|
|
|
|
$self->_flash_row(undef); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Daniel Westermann-Clark E<lt>danieltwc@cpan.orgE<gt> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright 2006-2008 Daniel Westermann-Clark, all rights reserved. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
154
|
|
|
|
|
|
|
under the same terms as Perl itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |