| 1 | package SQL::Abstract::Plugin::TableAlias; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; use warnings; our $VERSION = '0.04'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | with 'SQL::Abstract::Role::Plugin'; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | sub register_extensions { | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | my ($self, $sqla) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_extensions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | $sqla->plugin('+ExtraClauses'); | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | $sqla->wrap_expander(select => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | $self->cb('_alias_select', $_[0]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | sub _alias_select { | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 31 | ▶ | my ($self, $orig, $select, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_select: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 31 | ▶ | $args = $self->_alias_from_array($args) if (ref $args eq 'HASH' && ref $args->{from} eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args eq "HASH" and ref $args->{"from"} eq "ARRAY"
MC/DC0%0/2
ref $args eq "HASH" and ref $args->{"from"} eq "ARRAY"
ref $args eq "HASH"
ref $args->{"from"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $args eq "HASH"B= ref $args->{"from"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 31 | return $self->sqla->$orig($select, $args); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub _alias_from_array { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 31 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_from_array: called CC=36 SCAR=39.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 31 | ▶ | $args->{talias} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"talias"} ||= []
MC/DC100%1/1
$args->{"talias"} ||= []
$args->{"talias"}
Truth table100%2/2
A
A= $args->{"talias"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 31 | my ($i, @map, %columns) = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | for my $from (@{ $args->{from} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 96 | ▶ | my $ref = ref $from || ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $from || ''
MC/DC100%1/1
ref $from || ''
ref $from
Truth table100%2/2
A
A= ref $from
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 96 | ▶ | if ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 26 | ▶ | if ($from->{to}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 26 | ▶ | $from->{as} ||= scalar @{$args->{talias}} ? shift(@{$args->{talias}}) : ref $from->{to} ? $from->{to}->{-ident}->[0] : $from->{to}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$from->{"as"} ||= scalar @{$args->{"talias"};} ? shift @{$$args{"talias"};} : (ref $from->{"to"} ? $from->{"to"}{"-ident"}[0] : $from->{"to"})
MC/DC0%0/2
$from->{"as"} ||= scalar @{$args->{"talias"};} ? shift @{$$args{"talias"};} : (ref $from->{"to"} ? $from->{"to"}{"-ident"}[0] : $from->{"to"})
$from->{"as"}
scalar @{$args->{"talias"};} ? shift @{$$args{"talias"};} : (ref $from->{"to"} ? $from->{"to"}{"-ident"}[0] : $from->{"to"})
Truth table33%1/3
A ||= B
A= $from->{"as"}B= scalar @{$args->{"talias"};} ? shift @{$$args{"talias"};} : (ref $from->{"to"} ? $from->{"to"}{"-ident"}[0] : $from->{"to"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 26 | push @map, $from->{as}; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 26 | ▶ | if ($from->{on}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 26 | ▶ | if ($from->{on}->{-op}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if (scalar @{$from->{on}->{-op}->[1]->{-ident}} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | unshift @{$from->{on}{-op}[1]{-ident}}, $map[-2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | if (scalar @{$from->{on}->{-op}->[2]->{-ident}} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | unshift @{$from->{on}{-op}[2]{-ident}}, $map[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 24 | for my $on (keys %{$from->{on}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | ▶ | if (ref $from->{on}->{$on}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 24 | for my $oo (keys %{$from->{on}->{$on}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 24 | $from->{on}->{$on}->{$oo} = sprintf("%s.%s", $map[-1], $from->{on}->{$on}->{$oo}); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 24 | $from->{on}->{sprintf("%s.%s", $map[-2], $on)} = delete $from->{on}->{$on}; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | push @map, $from->{$_}->{-as} ||= shift(@{$args->{talias}}) || $_ | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | for ( sort keys %{ $from } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$from->{$_}{"-as"} ||= shift @{$$args{"talias"};} || $_
shift @{$$args{'talias'};} || $_
MC/DC0%0/3
$from->{$_}{"-as"} ||= shift @{$$args{"talias"};} || $_
$from->{$_}{"-as"}
shift @{$$args{'talias'};}
$_
Truth table0%0/4
A ||= B || C
A= $from->{$_}{"-as"}B= shift @{$$args{'talias'};}C= $_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if ($from->[1] eq 'as') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | push @map, $from->[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | push @map, shift @{$args->{talias}} || $from->[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift @{$$args{'talias'};} || $from->[0]
MC/DC0%0/2
shift @{$$args{'talias'};} || $from->[0]
shift @{$$args{'talias'};}
$from->[0]
Truth table66%2/3
A || B
A= shift @{$$args{'talias'};}B= $from->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | splice @{$from}, 1, 0, 'as', $map[-1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | for my $key ( keys %{ $from->[-1] } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | $from->[-1]->{_valid_column($key, $map[-2], {})} = _valid_column(delete $from->[-1]->{$key}, $map[-1], {}); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ▶ | } elsif (!$ref && $from !~ m/^-/) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ref || $from =~ /^-/
MC/DC50%1/2
$ref || $from =~ /^-/
$ref
$from =~ /^-/
Truth table66%2/3
A || B
A= $refB= $from =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 38 | ▶ | push @map, shift @{$args->{talias}} || $from; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift @{$$args{'talias'};} || $from
MC/DC0%0/2
shift @{$$args{'talias'};} || $from
shift @{$$args{'talias'};}
$from
Truth table66%2/3
A || B
A= shift @{$$args{'talias'};}B= $from
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 38 | splice @{$args->{from}}, $i, 1, { $from => { 'as' => $map[-1] } }; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 96 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ($args, %columns) = $self->_alias_select_array($args, \@map) | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 31 | ▶ | if ((ref($args->{select}) || "") eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $args->{'select'} || ''
MC/DC0%0/1
ref $args->{'select'} || ''
ref $args->{'select'}
Truth table50%1/2
A
A= ref $args->{'select'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 31 | my $where = ref $args->{where}; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 31 | ▶ | $where eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$where eq "ARRAY" and $self->_alias_where_array($args, $map[0], \%columns)
MC/DC0%0/2
$where eq "ARRAY" and $self->_alias_where_array($args, $map[0], \%columns)
$where eq "ARRAY"
$self->_alias_where_array($args, $map[0], \%columns)
Truth table66%2/3
A and B
A= $where eq "ARRAY"B= $self->_alias_where_array($args, $map[0], \%columns)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ? $self->_alias_where_hash($args, $map[0], \%columns) | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | : $where eq 'ARRAY' && $self->_alias_where_array($args, $map[0], \%columns); | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 31 | my $order_by = ref $args->{order_by}; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | $order_by eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | ? $self->_alias_order_by_hash($args, $map[0], \%columns) | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | : $order_by eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ? $self->_alias_order_by_array($args, $map[0], \%columns) | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 31 | ▶ | : defined $args->{order_by} && ! ref $order_by && $self->_alias_order_by_string($args, $map[0], \%columns); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $args->{"order_by"} and not ref $order_by and $self->_alias_order_by_string($args, $map[0], \%columns)
defined $args->{"order_by"} and not ref $order_by
MC/DC0%0/3
defined $args->{"order_by"} and not ref $order_by and $self->_alias_order_by_string($args, $map[0], \%columns)
defined $args->{"order_by"}
not ref $order_by
$self->_alias_order_by_string($args, $map[0], \%columns)
Truth table0%0/4
A and not(B) and C
A= defined $args->{"order_by"}B= not ref $order_byC= $self->_alias_order_by_string($args, $map[0], \%columns)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 31 | my $group_by = ref $args->{group_by}; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 31 | ▶ | $group_by eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$group_by eq "HASH" and $self->_alias_group_by_hash($args, $map[0], \%columns)
MC/DC0%0/2
$group_by eq "HASH" and $self->_alias_group_by_hash($args, $map[0], \%columns)
$group_by eq "HASH"
$self->_alias_group_by_hash($args, $map[0], \%columns)
Truth table66%2/3
A and B
A= $group_by eq "HASH"B= $self->_alias_group_by_hash($args, $map[0], \%columns)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ? $self->_alias_group_by_array($args, $map[0], \%columns) | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | : $group_by eq 'HASH' && $self->_alias_group_by_hash($args, $map[0], \%columns); | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 31 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub _alias_select_array { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 31 | ▶ | my ($self, $args, $map) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_select_array: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 31 | my ($i, $last_array, @select, %columns) = -1; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 31 | for my $sel ( @{ $args->{select} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 122 | my $ref = ref $sel; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 122 | ▶ | if ( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 33 | ▶ | for (my $l = 0; $l < scalar @{$sel}; $l++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 44 | ▶ | if (ref($sel->[$l]) || "" eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $sel->[$l] or
MC/DC100%1/1
ref $sel->[$l] or
ref $sel->[$l]
Truth table100%2/2
A
A= ref $sel->[$l]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | for my $key ( keys %{ $sel->[$l] } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $sel->[$l]{_valid_column($key, $map->[$i], {})} = delete $sel->[$l]{$key}; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $columns{$key} = $map->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | push @select, $sel->[$l]; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 43 | $columns{$sel->[$l]} = $map->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 43 | push @select, sprintf("%s.%s", $map->[$i], $sel->[$l]); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 33 | $last_array = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } elsif ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | $i++ if $i < 0 || $last_array && do { $last_array = 0; 1; }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$i < 0 or $last_array and do {
$last_array = 0;
1
}
$last_array and do {
$last_array = 0;
1
}
MC/DC0%0/3
$i < 0 or $last_array and do {
$last_array = 0;
1
}
$i < 0
$last_array
do {
$last_array = 0;
1
}
Truth table25%1/4
A or B and C
A= $i < 0B= $last_arrayC= do {
$last_array = 0;
1
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | for my $key ( keys %{ $sel } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | $sel->{_valid_column($key, $map->[$i], {})} = delete $sel->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | $columns{$key} = $map->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | push @select, $sel; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } elsif (! $ref) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 87 | ▶ | $i++ if $i < 0 || $last_array && do { $last_array = 0; 1; }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$i < 0 or $last_array and do {
$last_array = 0;
1
}
$last_array and do {
$last_array = 0;
1
}
MC/DC0%0/3
$i < 0 or $last_array and do {
$last_array = 0;
1
}
$i < 0
$last_array
do {
$last_array = 0;
1
}
Truth table50%2/4
A or B and C
A= $i < 0B= $last_arrayC= do {
$last_array = 0;
1
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 87 | $columns{$sel} = $map->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 87 | push @select, sprintf("%s.%s", $map->[$i], $sel); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 31 | $args->{select} = \@select; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 31 | return ($args, %columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | sub _alias_where_hash { | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 17 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_where_hash: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 17 | my %where; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 17 | for my $w (keys %{ $args->{where} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 39 | ▶ | if (ref $args->{$w} eq 'HASH' && $args->{$w}->{-alias}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args->{$w} eq "HASH" and $args->{$w}{"-alias"}
MC/DC0%0/2
ref $args->{$w} eq "HASH" and $args->{$w}{"-alias"}
ref $args->{$w} eq "HASH"
$args->{$w}{"-alias"}
Truth table33%1/3
A and B
A= ref $args->{$w} eq "HASH"B= $args->{$w}{"-alias"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $where{sprintf("%s.%s", delete $args->{where}->{$w}->{-alias}, $w)} = $args->{where}->{$w}; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 39 | $where{_valid_column($w, $default, $columns)} = $args->{where}->{$w}; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 17 | $args->{where} = \%where; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 17 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | sub _alias_where_array { | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_where_array: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 6 | ▶ | my $list = grep { $_ % 2 > 0 && $args->{where}->[$_] =~ m/-(and|or)/ } 0 .. scalar @{ $args->{where} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | ▶ | return $self->_alias_where_list($args, $default, $columns) if $list; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | for my $where (@{ $args->{where} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 16 | ▶ | my $ref = ref $where || ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $where || ''
MC/DC100%1/1
ref $where || ''
ref $where
Truth table100%2/2
A
A= ref $where
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 16 | ▶ | if ( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 12 | my $update = $self->_alias_where_hash({ where => $where }, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 12 | %{$where} = %{$update->{where}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub _alias_order_by_hash { | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_order_by_hash: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 9 | my %order_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | for my $w (keys %{ $args->{order_by} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 9 | my $ref = ref $args->{order_by}->{$w}; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | 9 | ▶ | if ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | my @order; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | for my $o ( @{ $args->{order_by}->{$w} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | push @order, _valid_column($o, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 5 | $order_by{$w} = \@order; | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } elsif ( ! $ref ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | $order_by{$w} = _valid_column($args->{order_by}{$w}, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 9 | $args->{order_by} = \%order_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 9 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub _alias_order_by_array { | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_order_by_array: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | for my $w ( @{ $args->{order_by} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 16 | ▶ | my $ref = ref $w || ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $w || ''
MC/DC100%1/1
ref $w || ''
ref $w
Truth table100%2/2
A
A= ref $w
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 16 | ▶ | if ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 8 | my $new = $self->_alias_order_by_hash({ order_by => $w }, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 8 | %{$w} = %{$new->{order_by}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | $args->{order_by}->[$i] = _valid_column($w, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 16 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub _alias_order_by_string { | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_order_by_string: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | $args->{order_by} = _valid_column($args->{order_by}, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | sub _alias_group_by_array { | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_group_by_array: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | my @group_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | for my $group (@{ $args->{group_by} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 7 | push @group_by, _valid_column($group, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | $args->{group_by} = \@group_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | sub _alias_group_by_hash { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | ▶ | my ($self, $args, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_alias_group_by_hash: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | my @group_by = shift @{ $args->{group_by}->{-op} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | for my $group (@{ $args->{group_by}->{-op} }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | $group->{-ident} = ref $group->{-ident} ? [map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | _valid_column($_, $default, $columns); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | } @{$group->{-ident}}] : _valid_column($group->{-ident}, $default, $columns); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | push @group_by, $group; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | $args->{group_by}->{-op} = \@group_by; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | return $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub _valid_column { | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 93 | ▶ | my ($column, $default, $columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_column: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 93 | ▶ | return $column if ($column =~ m/[^.]+\W+/); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 92 | ▶ | return sprintf( "%s.%s", ($columns->{$column} || $default), $column); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$columns->{$column} || $default
MC/DC0%0/2
$columns->{$column} || $default
$columns->{$column}
$default
Truth table66%2/3
A || B
A= $columns->{$column}B= $default
| |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||