| 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 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use vars qw(%defaults $VERSION); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | $VERSION = '1.00'; | |||||||||||||
| 11 | |||||||||||||||
| 12 | sub initialize | ||||||||||||||
| 13 | 3 | ▶ | { | ||||||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 14 | return { | ||||||||||||||
| 15 | 3 | counter => 0, | |||||||||||||
| 16 | ok => 1, | ||||||||||||||
| 17 | }; | ||||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | sub begin_work | ||||||||||||||
| 21 | 2 | ▶ | { | ||||||||||||
|
Subroutine
begin_work: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 22 | 2 | my ( $self, $storage) = @_; | |||||||||||||
| 23 | 2 | ▶ | return ( $storage->{counter}++) ? 1 : $self-> super; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | sub rollback | ||||||||||||||
| 27 | 2 | ▶ | { | ||||||||||||
|
Subroutine
rollback: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 28 | 2 | my ( $self, $storage) = @_; | |||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | $storage->{counter}--; | |||||||||||||
| 31 | |||||||||||||||
| 32 | 2 | ▶ | if ( $storage->{counter} > 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 1 | my $ok = $storage->{ok}; | |||||||||||||
| 34 | 1 | $storage->{ok} = 0; | |||||||||||||
| 35 | 1 | return $ok; | |||||||||||||
| 36 | } else { | ||||||||||||||
| 37 | 1 | $storage->{ok} = 1; | |||||||||||||
| 38 | 1 | return $self-> super; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | } | ||||||||||||||
| 41 | |||||||||||||||
| 42 | sub commit | ||||||||||||||
| 43 | 1 | ▶ | { | ||||||||||||
|
Subroutine
commit: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||
| 44 | 1 | my ( $self, $storage) = @_; | |||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | $storage->{counter}--; | |||||||||||||
| 47 | |||||||||||||||
| 48 | 1 | ▶ | if ( $storage->{counter} > 0) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 49 | 0 | return $storage->{ok}; | |||||||||||||
| 50 | } elsif ( $storage-> {ok}) { | ||||||||||||||
| 51 | 0 | return $self-> super; | |||||||||||||
| 52 | } else { | ||||||||||||||
| 53 | 1 | $storage->{ok} = 1; | |||||||||||||
| 54 | 1 | return $self-> rollback; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 1 | 1; | |||||||||||||
| 59 | |||||||||||||||
| 60 | __DATA__ | ||||||||||||||