dbMan/Extension/CmdTransaction.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 136 CC 17 SCAR 44.9
CC
17
Cov
0%
cmdcomplete
156.0
handle_action
42.0
IDENTIFICATION
2.0
CRAP 89.0
1 package DBIx::dbMan::Extension::CmdTransaction;
2  
3 use strict;
4 use base 'DBIx::dbMan::Extension';
5  
6 our $VERSION = '0.04';
7  
8 1;
9  
10 sub IDENTIFICATION { return "000001-000021-000004"; }
11  
12 sub preference { return 1500; }
13  
14 sub known_actions { return [ qw/COMMAND/ ]; }
15  
16 sub handle_action {
17 my ($obj,%action) = @_;
18  
19 if ($action{action} eq 'COMMAND') {
20 if ($action{cmd} =~ /^(begin\s+(transaction|work)|\\tb)$/i) {
21 $action{action} = 'TRANSACTION';
22 $action{operation} = 'begin';
23 } elsif ($action{cmd} =~ /^(end\s+(transaction|work)|\\ta|auto\s+(transaction|commit(\s+transaction)?))$/i) {
24 $action{action} = 'TRANSACTION';
25 $action{operation} = 'end';
26 } elsif ($action{cmd} =~ /^(commit(\s+transaction)?|\\tc)$/i) {
27 $action{action} = 'TRANSACTION';
28 $action{operation} = 'commit';
29 } elsif ($action{cmd} =~ /^(rollback(\s+transaction)?|\\tr)$/i) {
30 $action{action} = 'TRANSACTION';
31 $action{operation} = 'rollback';
32 }
33 }
34  
35 $action{processed} = 1;
36 return %action;
37 }
38  
39 sub cmdhelp {
40 return [
41 'BEGIN TRANSACTION' => 'Begin transaction block',
42 'END TRANSACTION' => 'End transaction block, change to auto commit transaction',
43 'COMMIT' => 'Commit transaction',
44 'ROLLBACK' => 'Rollback transaction'
45 ];
46 }
47  
48 sub cmdcomplete {
49 my ($obj,$text,$line,$start) = @_;
50 return () unless $obj->{-dbi}->current;
51 return ('tc','tr','ta') if $line =~ /^\s*\\[A-Z]*$/i and $obj->{-dbi}->in_transaction;
52 return ('tb') if $line =~ /^\s*\\[A-Z]*$/i and not $obj->{-dbi}->in_transaction;
53 return ('\tc','\tr','\ta') if $line =~ /^\s*$/ and $obj->{-dbi}->in_transaction;
54 return ('\tb') if $line =~ /^\s*$/ and not $obj->{-dbi}->in_transaction;
55 return qw/TRANSACTION WORK/ if $line =~ /^\s*BEGIN\s+\S*$/i and not $obj->{-dbi}->in_transaction;
56 return qw/TRANSACTION/ if $line =~ /^\s*AUTO\s+COMMIT\s+\S*$/i and $obj->{-dbi}->in_transaction;
57 return qw/TRANSACTION COMMIT/ if $line =~ /^\s*AUTO\s+\S*$/i and $obj->{-dbi}->in_transaction;
58 return qw/TRANSACTION WORK/ if $line =~ /^\s*(END|COMMIT|ROLLBACK)\s+\S*$/i and $obj->{-dbi}->in_transaction;
59 return qw/BEGIN/ if $line =~ /^\s*[A-Z]*$/i and not $obj->{-dbi}->in_transaction;
60 return qw/END AUTO COMMIT ROLLBACK/ if $line =~ /^\s*[A-Z]*$/i and $obj->{-dbi}->in_transaction;
61 return ();
62 }