| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Test::DBIC::ExpectedQueries::Query; | 
| 2 |  |  |  |  |  |  | $Test::DBIC::ExpectedQueries::Query::VERSION = '2.002'; | 
| 3 | 5 |  |  | 5 |  | 70870 | use Moo; | 
|  | 5 |  |  |  |  | 9800 |  | 
|  | 5 |  |  |  |  | 44 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | has sql                     => ( is => "ro", required => 1 ); | 
| 8 |  |  |  |  |  |  | has stack_trace             => ( is => "ro", required => 1 ); # Just a string | 
| 9 |  |  |  |  |  |  | has report_subselect_tables => (is => "ro", required => 1); | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | has table       => ( is => "rw" ); | 
| 12 |  |  |  |  |  |  | has operation   => ( is => "rw" ); | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 53 |  |  | 53 | 0 | 50575 | sub BUILD { shift->analyze_sql() } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub analyze_sql { | 
| 17 | 53 |  |  | 53 | 0 | 71 | my $self = shift; | 
| 18 | 53 |  |  |  |  | 105 | my $sql = $self->sql; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 53 |  |  |  |  | 132 | my $table = qr/ | 
| 21 |  |  |  |  |  |  | [^\w.]*     # optional quote | 
| 22 |  |  |  |  |  |  | ([\w.]+)  # capture table | 
| 23 |  |  |  |  |  |  | /x; | 
| 24 | 53 |  |  |  |  | 603 | my $select_table = qr/^ \s* select\s+ .+? \s? from \s+ $table (.*) /ixsm; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 53 | 100 |  |  |  | 1457 | if($sql =~ /^ \s* insert\s+ into \s+ $table /ixsm) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 27 | 2 |  |  |  |  | 8 | $self->table($1); | 
| 28 | 2 |  |  |  |  | 5 | $self->operation("insert"); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  | elsif($sql =~ /^ \s* update\s+ $table /ixsm) { | 
| 31 | 3 |  |  |  |  | 18 | $self->table($1); | 
| 32 | 3 |  |  |  |  | 8 | $self->operation("update"); | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | elsif($sql =~ /^ \s* delete\s+ from \s+ $table /ixsm) { | 
| 35 | 2 |  |  |  |  | 12 | $self->table($1); | 
| 36 | 2 |  |  |  |  | 5 | $self->operation("delete"); | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | elsif($sql =~ $select_table) { | 
| 39 | 9 |  |  |  |  | 40 | my ($table, $rest_sql) = ($1, $2); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 9 | 100 |  |  |  | 26 | if ($self->report_subselect_tables) { | 
| 42 | 4 |  | 100 |  |  | 44 | while ( uc($table) eq "SELECT" && ("select $rest_sql" =~ $select_table) ) { | 
| 43 | 6 |  |  |  |  | 41 | ($table, $rest_sql) = ($1, $2); | 
| 44 |  |  |  |  |  |  | } | 
| 45 | 4 | 100 | 66 |  |  | 19 | if ($table && uc($table) ne "SELECT") { | 
| 46 | 3 |  |  |  |  | 8 | $self->table($table); | 
| 47 | 3 |  |  |  |  | 7 | $self->operation("select"); | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | else { | 
| 51 | 5 |  |  |  |  | 18 | $self->table($table); | 
| 52 | 5 |  |  |  |  | 13 | $self->operation("select"); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 53 |  |  |  |  | 461 | return $self; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub display_sql { | 
| 60 | 10 |  |  | 10 | 0 | 18 | my $self = shift; | 
| 61 | 10 |  |  |  |  | 31 | return "SQL: (" . $self->sql . ")"; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub display_stack_trace { | 
| 65 | 5 |  |  | 5 | 0 | 6 | my $self = shift; | 
| 66 | 5 |  |  |  |  | 16 | return "     " . $self->stack_trace; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | 1; |