| 1 | package Daje::Workflow::GenerateSQL::Script::View; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Daje::Workflow::GenerateSQL::Base::Common', -base, -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 0 | ▶ | sub generate($self) { | ||||||||||||||||||||||||||
|
Subroutine
generate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 0 | my $data = $self->json; | |||||||||||||||||||||||||||
| 8 | 0 | my $name = $data->{name}; | |||||||||||||||||||||||||||
| 9 | 0 | my $fields = $self->_fields($data); | |||||||||||||||||||||||||||
| 10 | 0 | my $tables = $self->_tables($data); | |||||||||||||||||||||||||||
| 11 | 0 | my $conditions = $self->_conditions($data); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | my $template = $self->templates->get_data_section('view'); | |||||||||||||||||||||||||||
| 14 | 0 | $template =~ s/<<<name>>>/$name/; | |||||||||||||||||||||||||||
| 15 | 0 | $template =~ s/<<<tables>>>/$tables/; | |||||||||||||||||||||||||||
| 16 | 0 | $template =~ s/<<<fields>>>/$fields/; | |||||||||||||||||||||||||||
| 17 | 0 | $template =~ s/<<<conditions>>>/$conditions/; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | return $template; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub _conditions($self, $data) { | ||||||||||||||||||||||||||
|
Subroutine
_conditions: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 23 | 0 | my $conditions = ""; | |||||||||||||||||||||||||||
| 24 | 0 | my $length = scalar @{$data->{conditions}}; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | for(my $i = 0; $i < $length; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if(!length($conditions)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $conditions = @{$data->{conditions}}[$i]->{condition}; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if($i < $length - 1 and length(@{$data->{conditions}}[$i]->{conditionals})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
MC/DC0%0/2
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
$i < $length - 1
length @{$$data{"conditions"};}[$i]->{"conditionals"}
Truth table0%0/3
A and B
A= $i < $length - 1B= length @{$$data{"conditions"};}[$i]->{"conditionals"}
| |||||||||||||||||||||||||||||
| 29 | 0 | $conditions .= ' ' . @{$data->{conditions}}[$i]->{conditionals} | |||||||||||||||||||||||||||
| 30 | 0 | } | |||||||||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||||||||
| 32 | 0 | $conditions .= ' ' . @{$data->{conditions}}[$i]->{condition}; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if($i < $length - 1 and length(@{$data->{conditions}}[$i]->{conditionals})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
MC/DC0%0/2
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
$i < $length - 1
length @{$$data{"conditions"};}[$i]->{"conditionals"}
Truth table0%0/3
A and B
A= $i < $length - 1B= length @{$$data{"conditions"};}[$i]->{"conditionals"}
| |||||||||||||||||||||||||||||
| 34 | 0 | $conditions .= ' ' . @{$data->{conditions}}[$i]->{conditionals} | |||||||||||||||||||||||||||
| 35 | 0 | } | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 0 | return $conditions; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _tables($self, $data) { | ||||||||||||||||||||||||||
|
Subroutine
_tables: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 42 | 0 | my $tables = ""; | |||||||||||||||||||||||||||
| 43 | 0 | my $length = scalar @{$data->{tables}}; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | for(my $i = 0; $i < $length; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if(!length($tables)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | $tables = @{$data->{tables}}[$i]->{table_name}; | |||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | 0 | $tables .= ', ' . @{$data->{tables}}[$i]->{table_name};; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | return $tables; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _fields($self, $data) { | ||||||||||||||||||||||||||
|
Subroutine
_fields: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my $fields = ""; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | while(my($key, $value) = each %{$data->{fields}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if(!length($fields)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if($value eq $key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | $fields = $key; | |||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||
| 62 | 0 | $fields = $value . ' as ' . $key; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if($value eq $key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $fields .= ', ' . $key; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | $fields .= ', ' . $value . ' as ' . $key; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | return $fields; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||