File Coverage

blib/lib/Acrux/DBI/Tx.pm
Criterion Covered Total %
statement 6 18 33.3
branch 0 8 0.0
condition 0 5 0.0
subroutine 2 5 40.0
pod 2 2 100.0
total 10 38 26.3


line stmt bran cond sub pod time code
1             package Acrux::DBI::Tx;
2 5     5   36 use strict;
  5         11  
  5         256  
3 5     5   59 use utf8;
  5         11  
  5         65  
4              
5             =encoding utf8
6              
7             =head1 NAME
8              
9             Acrux::DBI::Tx - Transaction
10              
11             =head1 SYNOPSIS
12              
13             use Acrux::DBI::Tx;
14              
15             my $tx = Acrux::DBI::Tx->new( dbi => $dbi );
16             # . . .
17             $tx->commit;
18              
19             =head1 DESCRIPTION
20              
21             This is a scope guard for L transactions
22              
23             =head1 ATTRIBUTES
24              
25             This class implements the following attributes
26              
27             =head2 dbi
28              
29             dbi => $dbi
30              
31             The object this transaction belongs to. Note that this attribute is weakened
32              
33             =head1 METHODS
34              
35             This class implements the following methods
36              
37             =head2 commit
38              
39             $tx->commit;
40              
41             Commit transaction.
42              
43             =head2 new
44              
45             my $tx = Acrux::DBI::Tx->new( dbi => $dbi );
46             my $tx = Acrux::DBI::Tx->new( { dbi => $dbi } );
47              
48             Construct a new transaction object
49              
50             =head1 HISTORY
51              
52             See C file
53              
54             =head1 TO DO
55              
56             See C file
57              
58             =head1 SEE ALSO
59              
60             L, L
61              
62             =head1 AUTHOR
63              
64             Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE
65              
66             =head1 COPYRIGHT
67              
68             Copyright (C) 1998-2026 D&D Corporation
69              
70             =head1 LICENSE
71              
72             This program is distributed under the terms of the Artistic License Version 2.0
73              
74             See the C file or L for details
75              
76             =cut
77              
78             sub new {
79 0     0 1   my $class = shift;
80 0 0         my $args = scalar(@_) ? scalar(@_) > 1 ? {@_} : {%{$_[0]}} : {};
  0 0          
81             my $self = bless {
82             dbi => $args->{dbi},
83 0   0       rollback => $args->{rollback} // 1,
84             }, $class;
85 0           $self->{dbi}->begin;
86 0           return $self;
87             }
88             sub commit {
89 0     0 1   my $self = shift;
90 0 0         $self->{dbi}->commit if $self->{rollback};
91 0           $self->{rollback} = 0;
92             }
93             sub DESTROY {
94 0     0     my $self = shift;
95 0 0 0       if ($self->{rollback} && (my $dbi = $self->{dbi})) { $dbi->rollback }
  0            
96             }
97              
98             1;
99              
100             __END__