ExpectedQueries/Query.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 14 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 4 totaltotal 91.3% 63 / 69 CC 10 SCAR 20.1
CC
10
Cov
98%
analyze_sql
10.0
BEGIN
1.0
BUILD
1.0
CRAP 7.4
↑ Summary ExpectedQueries.pm »
1 package Test::DBIC::ExpectedQueries::Query;
2 5 $Test::DBIC::ExpectedQueries::Query::VERSION = '2.002';
3 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5  
6  
7 5 has sql => ( is => "ro", required => 1 );
8 5 has stack_trace => ( is => "ro", required => 1 ); # Just a string
9 5 has report_subselect_tables => (is => "ro", required => 1);
10  
11 5 has table => ( is => "rw" );
12 5 has operation => ( is => "rw" );
13  
14 53 ▶sub BUILD { shift->analyze_sql() }
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
15  
16 53 ▶sub analyze_sql {
Subroutine analyze_sql: called CC=10 SCAR=23.0
Pod undocumented
17 53 my $self = shift;
18 53 my $sql = $self->sql;
19  
20 53 my $table = qr/
21 [^\w.]* # optional quote
22 ([\w.]+) # capture table
23 /x;
24 53 my $select_table = qr/^ \s* select\s+ .+? \s? from \s+ $table (.*) /ixsm;
25  
26 53 ▶ if($sql =~ /^ \s* insert\s+ into \s+ $table /ixsm) {
Branch: 4 branches
BranchTrueFalseTotal
if ($sql =~ /^ \s* insert\s+ into \s+ $table /imsx) { } 2 51 53
elsif ($sql =~ /^ \s* update\s+ $table /imsx) { } 3 48 51
elsif ($sql =~ /^ \s* delete\s+ from \s+ $table /imsx) { } 2 46 48
elsif ($sql =~ /$select_table/imsx) { } 9 37 46
27 2 $self->table($1);
28 2 $self->operation("insert");
29 }
30 elsif($sql =~ /^ \s* update\s+ $table /ixsm) {
31 3 $self->table($1);
32 3 $self->operation("update");
33 }
34 elsif($sql =~ /^ \s* delete\s+ from \s+ $table /ixsm) {
35 2 $self->table($1);
36 2 $self->operation("delete");
37 }
38 elsif($sql =~ $select_table) {
39 9 my ($table, $rest_sql) = ($1, $2);
40  
41 9 ▶ if ($self->report_subselect_tables) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->report_subselect_tables) { } 4 5 9
42 4 ▶ while ( uc($table) eq "SELECT" && ("select $rest_sql" =~ $select_table) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $table eq "SELECT" and ("select $rest_sql") =~ /$select_table/) 6 4 10
Condition100%3/3
uc $table eq "SELECT" and ("select $rest_sql") =~ /$select_table/
!ll&&!rl&&r
316
MC/DC100%2/2
uc $table eq "SELECT" and ("select $rest_sql") =~ /$select_table/
uc $table eq "SELECT" ("select $rest_sql") =~ /$select_table/
Truth table100%3/3
A and B
A= uc $table eq "SELECT"B= ("select $rest_sql") =~ /$select_table/
ABresult
0X0
100
111
43 6 ($table, $rest_sql) = ($1, $2);
44 }
45 4 ▶ if ($table && uc($table) ne "SELECT") {
Branch: 1 branch
BranchTrueFalseTotal
if ($table and uc $table ne "SELECT") 3 1 4
Condition66%2/3
$table and uc $table ne "SELECT"
!ll&&!rl&&r
013
MC/DC50%1/2
$table and uc $table ne "SELECT"
$table uc $table ne "SELECT"
Truth table66%2/3
A and B
A= $tableB= uc $table ne "SELECT"
ABresult
0X0
100
111
46 3 $self->table($table);
47 3 $self->operation("select");
48 }
49 }
50 else {
51 5 $self->table($table);
52 5 $self->operation("select");
53 }
54 }
55  
56 53 return $self;
57 }
58  
59 10 ▶sub display_sql {
Subroutine display_sql: called CC=1 SCAR=0.0
Pod undocumented
60 10 my $self = shift;
61 10 return "SQL: (" . $self->sql . ")";
62 }
63  
64 5 ▶sub display_stack_trace {
Subroutine display_stack_trace: called CC=1 SCAR=0.0
Pod undocumented
65 5 my $self = shift;
66 5 return " " . $self->stack_trace;
67 }
68  
69 5 1;
↑ Summary ExpectedQueries.pm »