Script/View.pm

filter: Statementstmt 7.4% 4 / 54 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 20.0% 1 / 5 Podpod 0.0% 0 / 1 totaltotal 5.5% 5 / 90 CC 13 SCAR 35.3
CC
13
Cov
5%
_conditions
56.0
_fields
30.0
_tables
12.0
CRAP 34.2
« Script/Fields.pm ↑ Summary Manager/Sql.pm »
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
BranchTrueFalseTotal
if ($i < $length) 0 0 0
26 0 ▶ if(!length($conditions)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $conditions) { } 0 0 0
27 0 $conditions = @{$data->{conditions}}[$i]->{condition};
28 0 ▶ if($i < $length - 1 and length(@{$data->{conditions}}[$i]->{conditionals})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}) 0 0 0
Condition0%0/3
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}) 0 0 0
Condition0%0/3
$i < $length - 1 and length @{$$data{"conditions"};}[$i]->{"conditionals"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($i < $length) 0 0 0
45 0 ▶ if(!length($tables)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $tables) { } 0 0 0
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
BranchTrueFalseTotal
if (() = each %{$$data{"fields"};}) 0 0 0
58 0 ▶ if(!length($fields)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $fields) { } 0 0 0
59 0 ▶ if($value eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq $key) { } 0 0 0
60 0 $fields = $key;
61 } else {
62 0 $fields = $value . ' as ' . $key;
63 }
64 } else {
65 0 ▶ if($value eq $key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq $key) { } 0 0 0
66 0 $fields .= ', ' . $key;
67 } else {
68 0 $fields .= ', ' . $value . ' as ' . $key;
69 }
70 }
71 }
72 0 return $fields;
73 }
74  
75 1 1;
« Script/Fields.pm ↑ Summary Manager/Sql.pm »