| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | while ( uc($table) eq "SELECT" && ("select $rest_sql" =~ $select_table) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
uc $table eq "SELECT" and ("select $rest_sql") =~ /$select_table/
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/
| |||||||||||||||||||||||||||||
| 43 | 6 | ($table, $rest_sql) = ($1, $2); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 4 | ▶ | if ($table && uc($table) ne "SELECT") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$table and uc $table ne "SELECT"
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"
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||