line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ObjectDB::With; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
70047
|
use strict; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
146
|
|
4
|
5
|
|
|
5
|
|
30
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
2584
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '3.28'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
10
|
0
|
|
|
|
|
|
my (%params) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = {}; |
13
|
0
|
|
|
|
|
|
bless $self, $class; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
$self->{meta} = $params{meta}; |
16
|
0
|
|
|
|
|
|
$self->{with} = $params{with}; |
17
|
|
|
|
|
|
|
$self->{with} = [ $self->{with} ] |
18
|
0
|
0
|
0
|
|
|
|
if $self->{with} && ref $self->{with} ne 'ARRAY'; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $joins = { join => [] }; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
my @with = sort { (ref $a eq 'HASH' ? $a->{name} : $a) cmp (ref $b eq 'HASH' ? $b->{name} : $b) } |
|
|
0
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
grep { defined } @{ $self->{with} || [] }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my %seen; |
26
|
0
|
0
|
|
|
|
|
if (@with) { |
27
|
0
|
|
|
|
|
|
foreach my $with (@with) { |
28
|
0
|
|
|
|
|
|
my $meta = $self->{meta}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $name = $with; |
31
|
0
|
|
|
|
|
|
my $columns; |
32
|
0
|
0
|
|
|
|
|
if (ref $name eq 'HASH') { |
33
|
0
|
|
|
|
|
|
$name = $with->{name}; |
34
|
0
|
|
|
|
|
|
$columns = $with->{columns}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my @parts = split /[.]/xms, $name; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $seen = q{}; |
40
|
0
|
|
|
|
|
|
my $parent_join = $joins; |
41
|
0
|
|
|
|
|
|
foreach my $part (@parts) { |
42
|
0
|
|
|
|
|
|
$seen .= q{.} . $part; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $rel = $meta->get_relationship($part); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($seen{$seen}) { |
47
|
0
|
|
|
|
|
|
$parent_join = $seen{$seen}; |
48
|
0
|
|
|
|
|
|
$meta = $rel->class->meta; |
49
|
0
|
|
|
|
|
|
next; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $parent_as = $parent_join->{as}; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
my $name_prefix = $parent_as ? $parent_as . '_' : ''; |
55
|
|
|
|
|
|
|
my @joins = $rel->to_source( |
56
|
|
|
|
|
|
|
table => $parent_join->{as}, |
57
|
0
|
|
|
|
|
|
name_prefix => $name_prefix |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
foreach my $join (@joins) { |
61
|
0
|
|
|
|
|
|
push @{ $parent_join->{join} }, |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
source => $join->{table}, |
64
|
|
|
|
|
|
|
rel_name => $join->{as}, |
65
|
|
|
|
|
|
|
as => $name_prefix . $join->{as}, |
66
|
|
|
|
|
|
|
on => $join->{constraint}, |
67
|
|
|
|
|
|
|
op => $join->{join}, |
68
|
|
|
|
|
|
|
columns => $columns || $join->{columns}, |
69
|
0
|
|
0
|
|
|
|
join => [] |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$parent_join = $parent_join->{join}->[-1]; |
74
|
0
|
|
|
|
|
|
$seen{$seen} = $parent_join; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$meta = $rel->class->meta; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{joins} = $joins->{join}; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub to_joins { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $self->{joins}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |