| 1 | # ABSTRACT: Role for actions that are transactional | ||
| 2 | |||
| 3 | package Pinto::Role::Transactional; | ||
| 4 | |||
| 5 | 63 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 63 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 63 | ▶ | use Try::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 63 | ▶ | use Pinto::Util qw(throw); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | #------------------------------------------------------------------------------ | ||
| 13 | |||
| 14 | 63 | our $VERSION = '0.14'; # VERSION | |
| 15 | |||
| 16 | #------------------------------------------------------------------------------ | ||
| 17 | |||
| 18 | 63 | requires qw( execute repo ); | |
| 19 | |||
| 20 | #------------------------------------------------------------------------------ | ||
| 21 | |||
| 22 | 107 | ▶ | around execute => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 23 | 107 | my ( $orig, $self, @args ) = @_; | |
| 24 | |||
| 25 | 107 | $self->repo->txn_begin; | |
| 26 | |||
| 27 | 107 | ▶ | my $result = try { $self->$orig(@args); $self->repo->txn_commit } |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 28 | 107 | ▶ | catch { $self->repo->txn_rollback; throw $_ }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 29 | |||
| 30 | 99 | return $self->result; | |
| 31 | 63 | }; | |
| 32 | |||
| 33 | #------------------------------------------------------------------------------ | ||
| 34 | 63 | 1; | |
| 35 | |||
| 36 | __END__ | ||