File Coverage

blib/lib/DBIx/Roles/Transaction.pm
Criterion Covered Total %
statement 22 24 91.6
branch 6 8 75.0
condition n/a
subroutine 6 6 100.0
pod 0 4 0.0
total 34 42 80.9


line stmt bran cond sub pod time code
1             # $Id: Transaction.pm,v 1.3 2005/12/02 10:43:09 dk Exp $
2              
3             package DBIx::Roles::Transaction;
4              
5             # Allows nested begin_work/rollback/commit calls
6              
7 1     1   4 use strict;
  1         2  
  1         27  
8 1     1   4 use vars qw(%defaults $VERSION);
  1         1  
  1         234  
9              
10             $VERSION = '1.00';
11              
12             sub initialize
13             {
14             return {
15 3     3 0 29 counter => 0,
16             ok => 1,
17             };
18             }
19              
20             sub begin_work
21             {
22 2     2 0 5 my ( $self, $storage) = @_;
23 2 100       14 return ( $storage->{counter}++) ? 1 : $self-> super;
24             }
25              
26             sub rollback
27             {
28 2     2 0 5 my ( $self, $storage) = @_;
29            
30 2         5 $storage->{counter}--;
31              
32 2 100       5 if ( $storage->{counter} > 0) {
33 1         2 my $ok = $storage->{ok};
34 1         3 $storage->{ok} = 0;
35 1         6 return $ok;
36             } else {
37 1         3 $storage->{ok} = 1;
38 1         5 return $self-> super;
39             }
40             }
41              
42             sub commit
43             {
44 1     1 0 3 my ( $self, $storage) = @_;
45              
46 1         2 $storage->{counter}--;
47              
48 1 50       8 if ( $storage->{counter} > 0) {
    50          
49 0         0 return $storage->{ok};
50             } elsif ( $storage-> {ok}) {
51 0         0 return $self-> super;
52             } else {
53 1         2 $storage->{ok} = 1;
54 1         103 return $self-> rollback;
55             }
56             }
57              
58             1;
59              
60             __DATA__