[Catalyst-commits] r7698 - in Catalyst-Controller-DBIC-Transaction/1.0/trunk: . lib lib/Catalyst lib/Catalyst/Action lib/Catalyst/Action/DBIC lib/Catalyst/Controller lib/Catalyst/Controller/DBIC

ruoso at dev.catalyst.perl.org ruoso at dev.catalyst.perl.org
Tue May 6 22:04:53 BST 2008


Author: ruoso
Date: 2008-05-06 22:04:53 +0100 (Tue, 06 May 2008)
New Revision: 7698

Added:
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/DBIC/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/DBIC/Transaction.pm
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/DBIC/
   Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/DBIC/Transaction.pm
Log:
[C-C-DBIC-Transaction] Defining the module...

Added: Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/DBIC/Transaction.pm
===================================================================
--- Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/DBIC/Transaction.pm	                        (rev 0)
+++ Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Action/DBIC/Transaction.pm	2008-05-06 21:04:53 UTC (rev 7698)
@@ -0,0 +1,76 @@
+{   package Catalyst::Action::DBIC::Transaction;
+    use strict;
+    use warnings;
+    use base qw(Catalyst::Action);
+
+    sub execute {
+        my $self = shift;
+        my ( $controller, $c ) = @_;
+
+        my $schema_class = $controller->_dbic_transaction_schemas->{$self->name}
+          or die 'No schema class defined for DBIC::Transaction ActionClass';
+
+        my $wantarray = wantarray;
+        my ($return, @return, $success);
+
+        my $sub = sub {
+            if ($wantarray) {
+                @return = $self->NEXT::execute(@_);
+            } else {
+                $return = $self->NEXT::execute(@_);
+            }
+        };
+
+        $schema_class->txn_do($sub);
+
+        if ($wantarray) {
+            return @return;
+        } else {
+            return $return;
+        }
+    }
+
+};
+1;
+
+=head1 NAME
+
+Catalyst::Action::DBIC::Transaction - Encloses actions into transactions
+
+=head1 SYNOPSIS
+
+  use base qw(Catalyst::Controller::DBIC::Transaction);
+  sub foo :DBICTransaction('DB::Schema') {
+     do $something or die $!;
+  }
+
+=head1 DESCRIPTION
+
+This module enables the use of automatic transaction support into
+Catalyst Actions, it will associate a given action with the
+appropriate action class and save the DBIx::Class::Schema class name
+for later use.
+
+The action will be executed inside a txn_do, and a die inside that
+method will cause the transaction to be rolled back, as documented in
+DBIx::Class::Schema.
+
+This method will not, on the other hand, handle that exception, since
+txn_do will rethrow it. This means that this handling is not much
+intrusive in the action processing flow.
+
+=head1 AUTHORS
+
+Daniel Ruoso <daniel at ruoso.com>
+
+=head1 BUG REPORTS
+
+Please submit all bugs regarding C<Catalyst::Controller::DBIC::Transaction> to
+C<bug-catalyst-controller-dbic-transaction at rt.cpan.org>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut

Added: Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/DBIC/Transaction.pm
===================================================================
--- Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/DBIC/Transaction.pm	                        (rev 0)
+++ Catalyst-Controller-DBIC-Transaction/1.0/trunk/lib/Catalyst/Controller/DBIC/Transaction.pm	2008-05-06 21:04:53 UTC (rev 7698)
@@ -0,0 +1,63 @@
+{   package Catalyst::Controller::DBIC::Transaction;
+
+    use strict;
+    use warnings;
+    use base qw(Catalyst::Controller);
+
+    __PACKAGE__->mk_accessors qw(_dbic_transaction_schemas);
+
+    sub _parse_DBICTransaction_attr {
+        my ($self, $c, $name, $value) = @_;
+
+        $self->_dbic_transaction_schemas({}) unless
+          $self->_dbic_transaction_schemas({});
+
+        $self->_dbic_transaction_schemas->{$name} = $value;
+
+        ( ActionClass => 'DBIC::Transaction' );
+    }
+
+};
+1;
+
+=head1 NAME
+
+Catalyst::Controller::DBIC::Transaction - Encloses actions into transactions
+
+=head1 SYNOPSIS
+
+  use base qw(Catalyst::Controller::DBIC::Transaction);
+  sub foo :DBICTransaction('DB::Schema') {
+     do $something or die $!;
+  }
+
+=head1 DESCRIPTION
+
+This module enables the use of automatic transaction support into
+Catalyst Actions, it will associate a given action with the
+appropriate action class and save the DBIx::Class::Schema class name
+for later use.
+
+The action will be executed inside a txn_do, and a die inside that
+method will cause the transaction to be rolled back, as documented in
+DBIx::Class::Schema.
+
+This method will not, on the other hand, handle that exception, since
+txn_do will rethrow it. This means that this handling is not much
+intrusive in the action processing flow.
+
+=head1 AUTHORS
+
+Daniel Ruoso <daniel at ruoso.com>
+
+=head1 BUG REPORTS
+
+Please submit all bugs regarding C<Catalyst::Controller::DBIC::Transaction> to
+C<bug-catalyst-controller-dbic-transaction at rt.cpan.org>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut




More information about the Catalyst-commits mailing list