Oracle/SQLMaker/Joins.pm

filter: Statementstmt 92.8% 52 / 56 Branchbran 75.0% 21 / 28 Conditioncond 50.0% 9 / 18 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 77.5% 93 / 120 CC 23 SCAR 26.4
CC
23
Cov
80%
_recurse_oracle_joins
22.0
_oracle_joins
4.0
_recurse_from
3.2
CRAP 14.0
« Oracle/Diff/Column.pm ↑ Summary Oracle/Diff/Unique.pm »
1 package DBIO::Oracle::SQLMaker::Joins;
2 # ABSTRACT: Pre-ANSI Joins-via-Where-Clause Syntax for Oracle
3  
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.900007';
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base qw( DBIO::Oracle::SQLMaker );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 8 ▶sub select {
Subroutine select: called CC=2 SCAR=7.0
Pod documented
14 8 my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
15  
16 8 ▶ if (ref($table) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table eq "ARRAY") 8 0 8
17 8 $where = $self->_oracle_joins($where, @{ $table }[ 1 .. $#$table ]);
18 }
19  
20 8 return $self->next::method($table, $fields, $where, $rs_attrs, @rest);
21 }
22  
23 8 ▶sub _recurse_from {
Subroutine _recurse_from: called CC=3 SCAR=11.6
24 8 my ($self, $from, @join) = @_;
25  
26 8 my @sqlf = $self->_from_chunk_to_sql($from);
27  
28 8 for (@join) {
29 8 my ($to, $on) = @$_;
30  
31 8 ▶ if (ref $to eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to eq 'ARRAY') { } 0 8 8
32 0 push (@sqlf, $self->_recurse_from(@{ $to }));
33 }
34 else {
35 8 push (@sqlf, $self->_from_chunk_to_sql($to));
36 }
37 }
38  
39 8 return join q{, }, @sqlf;
40 }
41  
42 8 ▶sub _oracle_joins {
Subroutine _oracle_joins: called CC=4 SCAR=13.9
43 8 my ($self, $where, @join) = @_;
44 8 my $join_where = $self->_recurse_oracle_joins(@join);
45  
46 8 ▶ if (keys %$join_where) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$join_where) 8 0 8
47 8 ▶ if (!defined($where)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $where) { } 2 6 8
48 2 $where = $join_where;
49 } else {
50 6 ▶ if (ref($where) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where eq "ARRAY") 2 4 6
51 2 $where = { -or => $where };
52 }
53 6 $where = { -and => [ $join_where, $where ] };
54 }
55 }
56 8 return $where;
57 }
58  
59 8 ▶sub _recurse_oracle_joins {
Subroutine _recurse_oracle_joins: called CC=17 SCAR=30.9
60 8 my $self = shift;
61  
62 8 my @where;
63 8 for my $j (@_) {
64 8 my ($to, $on) = @{ $j };
65  
66 0 ▶ push @where, $self->_recurse_oracle_joins(@{ $to })
Branch: 1 branch
BranchTrueFalseTotal
if ref $to eq "ARRAY" 0 8 8
67 if (ref $to eq 'ARRAY');
68  
69 8 ▶ my $join_opts = ref $to eq 'ARRAY' ? $to->[0] : $to;
Branch: 1 branch
BranchTrueFalseTotal
ref $to eq 'ARRAY' ? : 0 8 8
70 8 my $left_join = q{};
71 8 my $right_join = q{};
72  
73 8 ▶ if (ref $join_opts eq 'HASH' and my $jt = $join_opts->{-join_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}) 6 2 8
Condition66%2/3
ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}
!ll&&!rl&&r
026
MC/DC50%1/2
ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}
ref $join_opts eq "HASH" my $jt = $join_opts->{"-join_type"}
Truth table66%2/3
A and B
A= ref $join_opts eq "HASH"B= my $jt = $join_opts->{"-join_type"}
ABresult
0X0
100
111
74 6 ▶ $self->throw_exception("Can't handle full outer joins in Oracle 8 yet!\n")
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /full/i 0 6 6
75 if $jt =~ /full/i;
76  
77 6 ▶ $left_join = q{(+)} if $jt =~ /left/i
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /left/i and not $jt =~ /inner/i 4 2 6
Condition66%2/3
$jt =~ /left/i and not $jt =~ /inner/i
!ll&&!rl&&r
204
MC/DC50%1/2
$jt =~ /left/i and not $jt =~ /inner/i
$jt =~ /left/i not $jt =~ /inner/i
Truth table66%2/3
A and not(B)
A= $jt =~ /left/iB= not $jt =~ /inner/i
ABresult
0X0
100
111
78 && $jt !~ /inner/i;
79  
80 6 ▶ $right_join = q{(+)} if $jt =~ /right/i
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /right/i and not $jt =~ /inner/i 2 4 6
Condition66%2/3
$jt =~ /right/i and not $jt =~ /inner/i
!ll&&!rl&&r
402
MC/DC50%1/2
$jt =~ /right/i and not $jt =~ /inner/i
$jt =~ /right/i not $jt =~ /inner/i
Truth table66%2/3
A and not(B)
A= $jt =~ /right/iB= not $jt =~ /inner/i
ABresult
0X0
100
111
81 && $jt !~ /inner/i;
82 }
83  
84 $on = $on->{-and}[0] if (
85 ref $on eq 'HASH'
86 and
87 keys %$on == 1
88 and
89 ref $on->{-and} eq 'ARRAY'
90 and
91 0 ▶ @{$on->{-and}} == 1
Branch: 1 branch
BranchTrueFalseTotal
if ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1 0 8 8
Condition33%3/9
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1
!ll&&!rl&&r
800
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY"
!ll&&!rl&&r
080
ref $on eq "HASH" and keys %$on == 1
!ll&&!rl&&r
008
MC/DC0%0/4
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1
ref $on eq "HASH" keys %$on == 1 ref $on->{"-and"} eq "ARRAY" @{$on->{"-and"};} == 1
Truth table20%1/5
A and B and C and D
A= ref $on eq "HASH"B= keys %$on == 1C= ref $on->{"-and"} eq "ARRAY"D= @{$on->{"-and"};} == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
92 );
93  
94 8 push @where, map { \do {
95 my ($sql) = $self->_recurse_where({
96 $_ => ( length ref $on->{$_}
97 ? $on->{$_}
98 8 ▶ : { -ident => $on->{$_} }
Branch: 1 branch
BranchTrueFalseTotal
length ref $on->{$_} ? : 4 4 8
99 )
100 });
101  
102 8 ▶ $sql =~ s/\s*\=/$left_join =/
Branch: 1 branch
BranchTrueFalseTotal
if $left_join 4 4 8
103 if $left_join;
104  
105 8 "$sql$right_join";
106 }
107 } sort keys %$on;
108 }
109  
110 8 return { -and => \@where };
111 }
112  
113  
114 2 1;
115  
116 __END__
« Oracle/Diff/Column.pm ↑ Summary Oracle/Diff/Unique.pm »