[Catalyst-commits] r8440 - in
trunk/Catalyst-Plugin-Session-Store-DBIC: .
lib/Catalyst/Plugin/Session/Store/DBIC
dwc at dev.catalyst.perl.org
dwc at dev.catalyst.perl.org
Mon Sep 22 20:59:15 BST 2008
Author: dwc
Date: 2008-09-22 20:59:15 +0100 (Mon, 22 Sep 2008)
New Revision: 8440
Modified:
trunk/Catalyst-Plugin-Session-Store-DBIC/Changes
trunk/Catalyst-Plugin-Session-Store-DBIC/Makefile.PL
trunk/Catalyst-Plugin-Session-Store-DBIC/lib/Catalyst/Plugin/Session/Store/DBIC/Delegate.pm
Log:
Add support for transactions to alleviate issues with duplicate flash rows
Modified: trunk/Catalyst-Plugin-Session-Store-DBIC/Changes
===================================================================
--- trunk/Catalyst-Plugin-Session-Store-DBIC/Changes 2008-09-22 18:34:10 UTC (rev 8439)
+++ trunk/Catalyst-Plugin-Session-Store-DBIC/Changes 2008-09-22 19:59:15 UTC (rev 8440)
@@ -1,9 +1,11 @@
Revision history for Catalyst-Plugin-Session-Store-DBIC
-0.07 Tue Sep 16 19:14:52 CDT 2008
- - Code was silently truncating storage to MySQL, rendering the
- session unreadable. Patched to check DBIx::Class size from
- column_info (if available).
+0.07
+ - Code was silently truncating storage to MySQL, rendering the
+ session unreadable. Patched to check DBIx::Class size from
+ column_info (if available)
+ - Wrap find_or_create calls in a transaction to (hopefully)
+ avoid issues with duplicate flash rows
0.06 Sat Sep 16 15:42:50 EDT 2006
- Convert to Catalyst::Plugin::Session::Store::Delegate (with
Modified: trunk/Catalyst-Plugin-Session-Store-DBIC/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-Session-Store-DBIC/Makefile.PL 2008-09-22 18:34:10 UTC (rev 8439)
+++ trunk/Catalyst-Plugin-Session-Store-DBIC/Makefile.PL 2008-09-22 19:59:15 UTC (rev 8440)
@@ -8,6 +8,7 @@
VERSION_FROM => 'lib/Catalyst/Plugin/Session/Store/DBIC.pm',
ABSTRACT_FROM => 'lib/Catalyst/Plugin/Session/Store/DBIC.pm',
PREREQ_PM => {
+ 'Carp' => 0,
'Catalyst' => '5.65', # For setup_finished
'Catalyst::Exception' => 0,
'Catalyst::Plugin::Session::Store::Delegate' => '0.02',
@@ -17,6 +18,7 @@
'NEXT' => 0,
'Storable' => 0,
'FindBin' => 0,
+ 'Scalar::Util' => 0,
'Test::More' => 0,
'Test::Warn' => 0,
},
Modified: trunk/Catalyst-Plugin-Session-Store-DBIC/lib/Catalyst/Plugin/Session/Store/DBIC/Delegate.pm
===================================================================
--- trunk/Catalyst-Plugin-Session-Store-DBIC/lib/Catalyst/Plugin/Session/Store/DBIC/Delegate.pm 2008-09-22 18:34:10 UTC (rev 8439)
+++ trunk/Catalyst-Plugin-Session-Store-DBIC/lib/Catalyst/Plugin/Session/Store/DBIC/Delegate.pm 2008-09-22 19:59:15 UTC (rev 8440)
@@ -4,6 +4,7 @@
use warnings;
use base qw/Class::Accessor::Fast/;
use Carp qw/carp/;
+use Scalar::Util qw/blessed/;
__PACKAGE__->mk_accessors(qw/model id_field data_field _session_row _flash_row/);
@@ -31,7 +32,7 @@
my $row = $self->_session_row;
unless ($row) {
- $row = $self->model->find_or_create({ $self->id_field => $key });
+ $row = $self->_load_row($key);
$self->_session_row($row);
}
@@ -50,13 +51,40 @@
my $row = $self->_flash_row;
unless ($row) {
- $row = $self->model->find_or_create({ $self->id_field => $key });
+ $row = $self->_load_row($key);
$self->_flash_row($row);
}
return $row;
}
+=head2 _load_row
+
+Load the specified session or flash row from the database. This is a
+wrapper around L<DBIx::Class::ResultSet/find_or_create> to add support
+for transactions.
+
+=cut
+
+sub _load_row {
+ my ($self, $key) = @_;
+
+ my $load_sub = sub {
+ return $self->model->find_or_create({ $self->id_field => $key })
+ };
+
+ my $row;
+ if (blessed $self->model and $self->model->can('result_source')) {
+ $row = $self->model->result_source->schema->txn_do($load_sub);
+ }
+ else {
+ # Fallback for DBIx::Class::DB
+ $row = $load_sub->();
+ }
+
+ return $row;
+}
+
=head2 expires
Return the expires row for this delegate. As with
More information about the Catalyst-commits
mailing list