| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # PerlORM - Object relational mapper (ORM) for Perl. PerlORM is Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # library that implements object-relational mapping. Its features are | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # much similar to those of Java's Hibernate library, but interface is | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # much different and easier to use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Alexey V. Akimov <akimov_alexey@sourceforge.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Copyright (C) 2005-2006 Alexey V. Akimov | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # This library is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # modify it under the terms of the GNU Lesser General Public | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # License as published by the Free Software Foundation; either | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # version 2.1 of the License, or (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # This library is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Lesser General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # You should have received a copy of the GNU Lesser General Public | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # License along with this library; if not, write to the Free Software | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Instance of the class represents tree data structure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # describing links between DB tables in joins. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | package ORM::Tjoin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | use ORM::TjoinNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | $VERSION=0.81; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ## CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ## use: ORM::Tjoin->new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ## ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ## class => STRING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ## alias => STRING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ## left_prop => STRING||undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ## prop => STRING||undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ## all_tables => BOOLEAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ## ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 53 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=29.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 53 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 53 | my %arg = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 53 | my $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 53 | ▶ | if( ! exists $arg{class} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 14 | $self = ORM::TjoinNull->new( null_class=>$arg{null_class} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | elsif( !UNIVERSAL::isa( $arg{class}, 'ORM' ) || $arg{class}->_is_initial ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not UNIVERSAL::isa($arg{"class"}, "ORM") or $arg{"class"}->_is_initial
MC/DC0%0/2
not UNIVERSAL::isa($arg{"class"}, "ORM") or $arg{"class"}->_is_initial
not UNIVERSAL::isa($arg{"class"}, "ORM")
$arg{"class"}->_is_initial
Truth table33%1/3
not(A) or B
A= not UNIVERSAL::isa($arg{"class"}, "ORM")B= $arg{"class"}->_is_initial
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | croak "Internal error! '$arg{class}' is not a valid descendant of ORM."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | $self = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | class => $arg{class}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | left_prop => ( $arg{left_prop}||'id' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | alias => ( $arg{alias}||undef ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | alias_num => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | cond => $arg{cond}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 39 | ▶ | fingerprint => ( ($arg{left_prop}||'id').' '.($arg{alias}||'').' '.($arg{cond}||'').' '.$arg{class} ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition70%7/10
$arg{'left_prop'} || 'id'
$arg{'alias'} || undef
$arg{'left_prop'} || 'id'
$arg{'alias'} || ''
$arg{'cond'} || ''
MC/DC100%1/1
$arg{'left_prop'} || 'id'
$arg{'left_prop'}
MC/DC0%0/1
$arg{'alias'} || undef
$arg{'alias'}
MC/DC100%1/1
$arg{'left_prop'} || 'id'
$arg{'left_prop'}
MC/DC0%0/1
$arg{'alias'} || ''
$arg{'alias'}
MC/DC0%0/1
$arg{'cond'} || ''
$arg{'cond'}
Truth table100%2/2
A
A= $arg{'left_prop'}
Truth table50%1/2
A
A= $arg{'alias'}
Truth table100%2/2
A
A= $arg{'left_prop'}
Truth table50%1/2
A
A= $arg{'alias'}
Truth table50%1/2
A
A= $arg{'cond'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | link => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 39 | ▶ | if( $self->{cond} && $self->{cond}->_tjoin->class ne $self->{class} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"cond"} and $self->{"cond"}->_tjoin->class ne $self->{"class"}
MC/DC0%0/2
$self->{"cond"} and $self->{"cond"}->_tjoin->class ne $self->{"class"}
$self->{"cond"}
$self->{"cond"}->_tjoin->class ne $self->{"class"}
Truth table33%1/3
A and B
A= $self->{"cond"}B= $self->{"cond"}->_tjoin->class ne $self->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | croak "Join condition class '".$self->{cond}->_tjoin->class."' does not match Tjoin class '$self->{class}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 39 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 39 | my @tables = $self->class->_db_tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 39 | ▶ | my $primary = $self->{left_prop} eq 'id' ? '' : $self->class->_prop2table( $self->{left_prop} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 39 | ▶ | for( my $i=0; $i < @tables; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 67 | ▶ | $self->{class_table}{$tables[$i]} = $tables[$i] eq $primary ? -10000 : -$i; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 39 | ▶ | if( $arg{all_tables} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | %{$self->{used_table}} = %{$self->{class_table}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 34 | $self->use_prop( $self->{left_prop} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 34 | ▶ | $self->use_prop( $arg{prop} ) if( $arg{prop} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 53 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 33 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=5 SCAR=17.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Must copy: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # class | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # left_prop | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # alias_num | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # fingerprint | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # link ( copy by content ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # class_table ( copy by reference ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # used_table ( copy by content ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # tables ( copy by content ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 33 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | my $copy = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | class => $self->{class}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | left_prop => $self->{left_prop}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | alias => $self->{alias}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | alias_num => $self->{alias_num}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | cond => $self->{cond}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | fingerprint => $self->{fingerprint}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | class_table => $self->{class_table}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 33 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 33 | ▶ | %{$copy->{used_table}} = %{$self->{used_table}} if( $self->{used_table} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | @{$copy->{tables}} = @{$self->{tables}} if( $self->{tables} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 33 | for my $prop ( keys %{$self->{link}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | for my $fingerprint ( keys %{$self->{link}{$prop}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $copy->{link}{$prop}{$fingerprint} = $self->{link}{$prop}{$fingerprint}->copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 33 | return bless $copy, ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ## PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 279 | ▶ | sub class { $_[0]->{class}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub null_class { $_[0]->{class}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
null_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | ▶ | sub fingerprint { $_[0]->{fingerprint}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fingerprint: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | sub sql_cond_str | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_cond_str: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | my $sql = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | if( $self->{cond} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $sql = ' AND ' . $self->{cond}->_sql_str( tjoin=>$self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub sql_table_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_table_list: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 12 | my $nested = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 12 | my $tables = $self->tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | my $sql = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | #$self->assign_aliases unless( $self->{alias_num} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 12 | ▶ | for( my $i=0; $i < @$tables; $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 16 | ▶ | if( $i == 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | ▶ | $sql .= "\n ".$self->table_as_alias( $tables->[$i] ) unless( $nested ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | ▶ | $sql .= | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$nested || ''
MC/DC100%1/1
$nested || ''
$nested
Truth table100%2/2
A
A= $nested
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | "\n".($nested||'').' '.($nested ? 'LEFT' : 'INNER')." JOIN ".$self->table_as_alias( $tables->[$i] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | . " ON( " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | . $self->full_field_name( 'id', $tables->[0] ) . '=' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | . $self->full_field_name( 'id', $tables->[$i] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | . " )"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | for my $prop ( keys %{$self->{link}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | for my $fingerprint ( keys %{$self->{link}{$prop}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | $sql .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | "\n".($nested||'')." LEFT JOIN " . $self->{link}{$prop}{$fingerprint}->first_basic_table_as_alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | . " ON( " | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | . $self->full_field_name( $prop ) . '=' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | . $self->{link}{$prop}{$fingerprint}->full_left_field_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | . $self->{link}{$prop}{$fingerprint}->sql_cond_str | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$nested || ''
MC/DC0%0/1
$nested || ''
$nested
Truth table50%1/2
A
A= $nested
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | . " )"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | $sql .= $self->{link}{$prop}{$fingerprint}->sql_table_list( ($nested||'').' ' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$nested || ''
MC/DC0%0/1
$nested || ''
$nested
Truth table50%1/2
A
A= $nested
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 12 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | sub text | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $nested = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $text .= $self->class . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | for my $prop ( keys %{$self->{link}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | for my $fingerprint ( keys %{$self->{link}{$prop}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | $text .= | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | $nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | . $prop | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | . ' -> ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | . $self->{link}{$prop}{$fingerprint}->text( $nested.' ' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sub sql_select_basic_tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sql_select_basic_tables: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | my $tables = $self->tables; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | my $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | #$self->assign_aliases unless( $self->{alias_num} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | for my $table ( @{$self->tables} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | $sql .= ", " if( $sql ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | $sql .= $self->class->ORM::qt( $self->table_alias_or_name( $table ) ) . '.*'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | return $sql; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | sub corresponding_node | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 65 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
corresponding_node: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 65 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 65 | my $tjoin = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 65 | my $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # if( $self->class eq $tjoin->class ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 65 | my $prop = (keys %{$tjoin->{link}})[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 65 | ▶ | if( $prop ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 7 | my $fingerprint = (keys %{$tjoin->{link}{$prop}})[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | ▶ | if( $self->{link}{$prop}{$fingerprint} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $node = $self->{link}{$prop}{$fingerprint}->corresponding_node | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 7 | $tjoin->{link}{$prop}{$fingerprint} | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 58 | $node = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 65 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ## TABLES PROPERTIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | sub tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 75 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 75 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 75 | ▶ | if( ! defined $self->{tables} || ! @{$self->{tables}} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"tables"} and @{$self->{"tables"};}
MC/DC50%1/2
defined $self->{"tables"} and @{$self->{"tables"};}
defined $self->{"tables"}
@{$self->{"tables"};}
Truth table66%2/3
A and B
A= defined $self->{"tables"}B= @{$self->{"tables"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 37 | ▶ | if( defined $self->{used_table} && %{$self->{used_table}} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"used_table"} and %{$self->{"used_table"};}
MC/DC50%1/2
defined $self->{"used_table"} and %{$self->{"used_table"};}
defined $self->{"used_table"}
%{$self->{"used_table"};}
Truth table66%2/3
A and B
A= defined $self->{"used_table"}B= %{$self->{"used_table"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 32 | @{$self->{tables}} = sort { $self->{used_table}{$a} <=> $self->{used_table}{$b} } keys %{$self->{used_table}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 5 | $self->{tables}[0] = $self->class->_db_table( 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 75 | return $self->{tables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 16 | ▶ | sub tables_count { scalar @{ $_[0]->tables }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | sub select_basic_tables { $_[0]->tables; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_basic_tables: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | ▶ | sub first_basic_table_alias { $_[0]->table_alias_or_name( $_[0]->tables->[0] ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_basic_table_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | sub first_basic_table_as_alias { $_[0]->table_as_alias( $_[0]->tables->[0] ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_basic_table_as_alias: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | sub table_alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 62 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_alias: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 62 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 62 | my $table = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 62 | my $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 62 | ▶ | if( $self->{alias_num} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 36 | ▶ | $alias = '_T'.$self->{alias_num}.($self->{alias} ? '_'.$self->{alias} : '').'_'.$table; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 62 | return $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | sub table_alias_or_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_alias_or_name: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | my $table = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | ▶ | return $self->table_alias( $table ) || $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->table_alias($table) || $table
MC/DC0%0/2
$self->table_alias($table) || $table
$self->table_alias($table)
$table
Truth table66%2/3
A || B
A= $self->table_alias($table)B= $table
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | sub table_as_alias | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_as_alias: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 16 | my $table = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 16 | my $alias = $self->table_alias( $table ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 16 | ▶ | if( $alias ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 8 | $alias = $self->class->ORM::qt( $table ).' AS '.$self->class->ORM::qt( $alias ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 8 | $alias = $self->class->ORM::qt( $table ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 16 | return $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | sub full_field_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 42 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
full_field_name: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 42 | my $prop = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 42 | ▶ | my $table = shift || ( $prop eq 'id' ? $self->tables->[0] : $self->class->_prop2table( $prop ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
shift() || ($prop eq 'id' ? $self->tables->[0] : $self->class->_prop2table($prop))
MC/DC0%0/2
shift() || ($prop eq 'id' ? $self->tables->[0] : $self->class->_prop2table($prop))
shift()
($prop eq 'id' ? $self->tables->[0] : $self->class->_prop2table($prop))
Truth table66%2/3
A || B
A= shift()B= ($prop eq 'id' ? $self->tables->[0] : $self->class->_prop2table($prop))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 42 | my $alias = $self->table_alias( $table ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 42 | my $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 42 | ▶ | if( $alias ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 26 | $name = $self->class->ORM::qt( $alias ).'.'.$self->class->ORM::qt( $prop ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 16 | $name = $self->class->ORM::qt( $prop ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 42 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | sub full_left_field_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
full_left_field_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | return $self->full_field_name( $self->{left_prop}, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ## METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | sub use_prop | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 75 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
use_prop: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 75 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 75 | my $prop = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 75 | ▶ | if( $prop eq 'id' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | elsif( $prop eq 'class' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | my $table = $self->class->_db_table( 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 2 | ▶ | unless( exists $self->{used_table}{$table} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | $self->{used_table}{$table} = $self->{class_table}{$table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | delete $self->{tables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 34 | my $table = $self->class->_prop2table( $prop ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 34 | ▶ | unless( exists $self->{used_table}{$table} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 26 | $self->{used_table}{$table} = $self->{class_table}{$table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 26 | delete $self->{tables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | sub assign_aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
assign_aliases: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | ▶ | my $alias = shift||1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 1
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 12 | $self->{alias_num} = $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 12 | for my $prop ( keys %{$self->{link}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | for my $fingerprint ( keys %{$self->{link}{$prop}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | $alias = $self->{link}{$prop}{$fingerprint}->assign_aliases( $alias+1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 12 | ▶ | $self->{alias_num} = undef if( $self->{alias_num} == 1 && $alias == 1 && $self->tables_count == 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"alias_num"} == 1 and $alias == 1 and $self->tables_count == 1
$self->{"alias_num"} == 1 and $alias == 1
MC/DC100%3/3
$self->{"alias_num"} == 1 and $alias == 1 and $self->tables_count == 1
$self->{"alias_num"} == 1
$alias == 1
$self->tables_count == 1
Truth table100%4/4
A and B and C
A= $self->{"alias_num"} == 1B= $alias == 1C= $self->tables_count == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | return $alias; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | ## use: $tjoin->link( $prop => $tjoin ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | sub link | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
link: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 8 | my $prop = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 8 | my $tjoin = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 8 | $self->{alias_num} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 8 | ▶ | if( $self->class->_has_prop( $prop ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 8 | $self->{link}{ $prop }{ $tjoin->fingerprint } = $tjoin; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 8 | $self->use_prop( $prop ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | croak "Can't link tjoin '".$tjoin->class."' to property '$prop' (class '".$self->class."' doesn't have it)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | sub merge | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 26 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge: called CC=9 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 26 | my $tjoin = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 26 | ▶ | if( ref $tjoin ne 'ORM::TjoinNull' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 25 | ▶ | if( UNIVERSAL::isa( $self->class, $tjoin->class ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # Do nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | elsif( UNIVERSAL::isa( $tjoin->class, $self->class ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->{class} = $tjoin->class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | %{$self->{class_table}} = %{$tjoin->{class_table}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | croak "Internal error! Can't merge, '$self->{class}' and '".$tjoin->class."' are incompatible."; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 25 | $self->{alias_num} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 25 | for my $table ( @{ $tjoin->tables } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 25 | ▶ | unless( $self->{used_table}{$table} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 13 | $self->{used_table}{$table} = $self->{class_table}{$table}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 13 | delete $self->{tables}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 25 | for my $prop ( keys %{$tjoin->{link}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 7 | for my $fingerprint ( keys %{$tjoin->{link}{$prop}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 7 | ▶ | if( exists $self->{link}{$prop}{$fingerprint} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 6 | $self->{link}{$prop}{$fingerprint}->merge( $tjoin->{link}{$prop}{$fingerprint} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | $self->link( $prop => $tjoin->{link}{$prop}{$fingerprint}->copy ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||