| 1 | package Database::Async::Transaction; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = '0.019'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use parent qw(Database::Async::DB); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Database::Async::Transaction - represents a single database transaction in L<Database::Async> | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Class::Method::Modifiers qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head2 new | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Instantiates the transaction. This is not intended to be called directly; | ||||||||||||||||||||||||||||
| 30 | that's normally handled by L<Database::Async> itself. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | Scalar::Util::weaken($args{database} || die 'expected database parameter'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'database'} || die('expected database parameter')
MC/DC0%0/1
$args{'database'} || die('expected database parameter')
$args{'database'}
Truth table0%0/2
A
A= $args{'database'}
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $args{open} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"open"} //= 0
MC/DC0%0/1
$args{"open"} //= 0
$args{"open"}
Truth table0%0/2
A
A= $args{"open"}
| |||||||||||||||||||||||||||||
| 38 | 0 | bless \%args, $class | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub database { shift->{database} } | ||||||||||||||||||||||||||
|
Subroutine
database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub begin { | ||||||||||||||||||||||||||
|
Subroutine
begin: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | my $query = Database::Async::Query->new( | |||||||||||||||||||||||||||
| 46 | db => $self->database, | ||||||||||||||||||||||||||||
| 47 | sql => 'begin', | ||||||||||||||||||||||||||||
| 48 | bind => [], | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | 0 | $query->single | |||||||||||||||||||||||||||
| 51 | ->completed | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub pool { shift->{pool} } | ||||||||||||||||||||||||||
|
Subroutine
pool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub completed { Future->done } | ||||||||||||||||||||||||||
|
Subroutine
completed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | #sub do { | ||||||||||||||||||||||||||||
| 59 | # my ($self, $sql, %args) = @_; | ||||||||||||||||||||||||||||
| 60 | # $self->query($sql => %args); | ||||||||||||||||||||||||||||
| 61 | #} | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | fresh commit => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | die 'transaction no longer active' unless $self->{open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | Future->done->on_ready(sub { $self->{open} = 0 }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 67 | 5 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | fresh rollback => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 71 | 0 | ▶ | return Future->done unless delete $self->{has_activity}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | die 'transaction no longer active' unless $self->{open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | Future->done->on_ready(sub { $self->{open} = 0 }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 74 | 5 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return unless $self->{open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $self->rollback->retain; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | before [@Database::Async::Query::METHODS] => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->{has_activity} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"has_activity"} //= 1
MC/DC0%0/1
$self->{"has_activity"} //= 1
$self->{"has_activity"}
Truth table0%0/2
A
A= $self->{"has_activity"}
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $self->{open} //= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"open"} //= 1
MC/DC0%0/1
$self->{"open"} //= 1
$self->{"open"}
Truth table0%0/2
A
A= $self->{"open"}
| |||||||||||||||||||||||||||||
| 87 | 5 | }; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub diagnostics { | ||||||||||||||||||||||||||
|
Subroutine
diagnostics: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | die 'need a valid pool instance' unless my $pool = $self->pool; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | die 'pool does not appear to be correct type' unless $pool->DOES('Database::Async::Pool'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | die 'inconsistent activity/open status' if $self->{open} and !$self->{has_activity}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"open"} and not $self->{"has_activity"}
MC/DC0%0/2
$self->{"open"} and not $self->{"has_activity"}
$self->{"open"}
not $self->{"has_activity"}
Truth table0%0/3
A and not(B)
A= $self->{"open"}B= not $self->{"has_activity"}
| |||||||||||||||||||||||||||||
| 94 | 0 | Future->done; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Tom Molesworth C<< <TEAM@cpan.org> >> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Copyright Tom Molesworth 2011-2023. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||