| 1 | package Mojo::MySQL5::Transaction; | ||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 7 | has 'db'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 7 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 8 | 0 | ▶ | return unless $self->{rollback} and $self->db; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"rollback"} and $self->db
MC/DC0%0/2
$self->{"rollback"} and $self->db
$self->{"rollback"}
$self->db
Truth table0%0/3
A and B
A= $self->{"rollback"}B= $self->db
| |||||||||||||||||||||||||||||
| 9 | 0 | local($@); | |||||||||||||||||||||||||||
| 10 | 0 | $self->db->query('ROLLBACK'); | |||||||||||||||||||||||||||
| 11 | 0 | $self->db->query('SET autocommit=1'); | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub commit { | ||||||||||||||||||||||||||
|
Subroutine
commit: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | return unless delete $self->{rollback}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | $self->db->query('COMMIT'); | |||||||||||||||||||||||||||
| 18 | 0 | $self->db->query('SET autocommit=1'); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 0 | shift->SUPER::new(@_, rollback => 1); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 7 | 1; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =encoding utf8 | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Mojo::MySQL5::Transaction - Transaction | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | use Mojo::MySQL5::Transaction; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $tx = Mojo::MySQL5::Transaction->new(db => $db); | ||||||||||||||||||||||||||||
| 38 | $tx->commit; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | L<Mojo::MySQL5::Transaction> is a cope guard for transactions started by | ||||||||||||||||||||||||||||
| 43 | $db->L<begin|Mojo::MySQL5::Database/"begin">. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | L<Mojo::MySQL5::Transaction> implements the following attributes. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head2 db | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | my $db = $tx->db; | ||||||||||||||||||||||||||||
| 52 | $tx = $tx->db(Mojo::MySQL5::Database->new); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | L<Mojo::MySQL5::Database> object this transaction belongs to. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 METHODS | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | L<Mojo::MySQL5::Transaction> inherits all methods from L<Mojo::Base> and | ||||||||||||||||||||||||||||
| 59 | implements the following ones. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head2 commit | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | $tx = $tx->commit; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Commit transaction. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head2 new | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | my $tx = Mojo::MySQL5::Transaction->new; | ||||||||||||||||||||||||||||
| 70 | my $tx = Mojo::MySQL5::Transaction->new(db => Mojo::MySQL5::Database->new); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Construct a new L<Mojo::MySQL5::Transaction> object. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | L<Mojo::MySQL5>. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||