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