Benchmark/Query.pm

filter: Statementstmt 21.8% 12 / 55 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 5 totaltotal 17.6% 15 / 85 CC 10 SCAR 24.3
CC
10
Cov
17%
new
20.0
execute_query
12.0
start_transaction
12.0
CRAP 11.4
« Benchmark/Query/common.pm ↑ Summary
1 package Tapper::Benchmark::Query;
2 4 our $AUTHORITY = 'cpan:TAPPER';
3 # ABSTRACT: Tapper::Benchmark - querying - base class
4 4 $Tapper::Benchmark::Query::VERSION = '5.0.0';
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
10  
11 0 my ( $s_self, $hr_atts ) = @_;
12  
13 0 my $or_self = bless {}, $s_self;
14  
15 0 for my $s_key (qw/ config dbh /) {
16 0 ▶ if (! $hr_atts->{$s_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hr_atts->{$s_key}) 0 0 0
17 0 require Carp;
18 0 Carp::confess("missing parameter '$s_key'");
19 }
20 }
21  
22 0 $or_self->{dbh} = $hr_atts->{dbh};
23 0 ▶ $or_self->{debug} = $hr_atts->{debug} || 0;
Condition0%0/2
$hr_atts->{'debug'} || 0
l!l
00
MC/DC0%0/1
$hr_atts->{'debug'} || 0
$hr_atts->{'debug'}
Truth table0%0/2
A
A= $hr_atts->{'debug'}
Aresult
11
00
24 0 $or_self->{config} = $hr_atts->{config};
25  
26 0 return $or_self;
27  
28 }
29  
30 0 ▶sub execute_query {
Subroutine execute_query: not called CC=3 SCAR=24.8
Pod undocumented
31  
32 0 my ( $or_self, $s_statement, @a_vals ) = @_;
33  
34 0 ▶ if ( $or_self->{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"debug"}) 0 0 0
35 0 warn $s_statement . ' (' . (join ',', @a_vals) . ')';
36 }
37  
38 0 local $or_self->{dbh}{RaiseError} = 1;
39  
40 0 my $s_key = Digest::MD5::md5($s_statement);
41 0 ▶ if ( $or_self->{prepared}{$s_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{'prepared'}{$s_key}) { } 0 0 0
42 0 $or_self->{prepared}{$s_key}->finish();
43 }
44 else {
45 0 $or_self->{prepared}{$s_key} = $or_self->{dbh}->prepare( $s_statement );
46 }
47  
48 0 $or_self->{prepared}{$s_key}->execute( @a_vals );
49  
50 0 return $or_self->{prepared}{$s_key};
51  
52 }
53  
54 0 ▶sub last_insert_id {
Subroutine last_insert_id: not called CC=1 SCAR=6.9
Pod undocumented
55  
56 0 my ( $or_self, $s_table, $s_column ) = @_;
57  
58 return $or_self->{dbh}->last_insert_id(
59 0 undef, undef, $s_table, $s_column,
60 );
61  
62 }
63  
64 0 ▶sub start_transaction {
Subroutine start_transaction: not called CC=3 SCAR=24.8
Pod undocumented
65  
66 0 my ( $or_self ) = @_;
67  
68 0 local $or_self->{dbh}{RaiseError} = 1;
69  
70 0 eval {
71 0 $or_self->{old_AutoCommit} = $or_self->{dbh}{AutoCommit};
72 0 $or_self->{dbh}{AutoCommit} = 0;
73 };
74 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
75 0 ▶ if ( $or_self->{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"debug"}) 0 0 0
76 0 require Carp;
77 0 Carp::cluck('Transactions not supported by your database');
78 }
79 }
80 else {
81 0 $or_self->{transaction_supported} = 1;
82 }
83  
84 0 return 1;
85  
86 }
87  
88 0 ▶sub finish_transaction {
Subroutine finish_transaction: not called CC=3 SCAR=24.8
Pod undocumented
89  
90 0 my ( $or_self, $s_error ) = @_;
91  
92 0 ▶ if ( $or_self->{transaction_supported} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($or_self->{"transaction_supported"}) 0 0 0
93  
94 0 local $or_self->{dbh}{RaiseError} = 1;
95  
96 0 ▶ if ( $s_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_error) { } 0 0 0
97 0 require Carp;
98 0 Carp::confess("transaction failed: $s_error");
99 0 $or_self->{dbh}->rollback();
100 }
101 else {
102 0 $or_self->{dbh}->commit();
103 }
104  
105 0 $or_self->{dbh}{AutoCommit} = $or_self->{old_AutoCommit};
106  
107 }
108  
109 0 return 1;
110  
111 }
112  
113 4 1;
114  
115 __END__
« Benchmark/Query/common.pm ↑ Summary