File Coverage

blib/lib/Pinto/Role/Transactional.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Role for actions that are transactional
2              
3             package Pinto::Role::Transactional;
4              
5 51     51   31495 use Moose::Role;
  51         122  
  51         464  
6 51     51   275558 use MooseX::MarkAsMethods ( autoclean => 1 );
  51         124  
  51         483  
7              
8 51     51   164954 use Try::Tiny;
  51         134  
  51         3788  
9              
10 51     51   330 use Pinto::Util qw(throw);
  51         114  
  51         11000  
11              
12             #------------------------------------------------------------------------------
13              
14             our $VERSION = '0.14'; # VERSION
15              
16             #------------------------------------------------------------------------------
17              
18             requires qw( execute repo );
19              
20             #------------------------------------------------------------------------------
21              
22             around execute => sub {
23             my ( $orig, $self, @args ) = @_;
24              
25             $self->repo->txn_begin;
26              
27             my $result = try { $self->$orig(@args); $self->repo->txn_commit }
28             catch { $self->repo->txn_rollback; throw $_ };
29              
30             return $self->result;
31             };
32              
33             #------------------------------------------------------------------------------
34             1;
35              
36             __END__
37              
38             =pod
39              
40             =encoding UTF-8
41              
42             =for :stopwords Jeffrey Ryan Thalhammer
43              
44             =head1 NAME
45              
46             Pinto::Role::Transactional - Role for actions that are transactional
47              
48             =head1 VERSION
49              
50             version 0.14
51              
52             =head1 AUTHOR
53              
54             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
55              
56             =head1 COPYRIGHT AND LICENSE
57              
58             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
59              
60             This is free software; you can redistribute it and/or modify it under
61             the same terms as the Perl 5 programming language system itself.
62              
63             =cut