line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Maker::Plugin::JoinSelect; |
2
|
2
|
|
|
2
|
|
5849
|
use 5.008001; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
87
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
23
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
143
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use Carp (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
797
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw/join_select/; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub join_select { |
11
|
8
|
|
|
8
|
1
|
15571
|
my ($self, $base_table, $join_conditoins, $fields, $where, $opt) = @_; |
12
|
8
|
|
|
|
|
17
|
my @join_conditions = @$join_conditoins; |
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
|
|
33
|
my @joins; |
15
|
8
|
|
|
|
|
33
|
while ( my ($table, $join_cond) = splice @join_conditions, 0, 2) { |
16
|
10
|
|
|
|
|
14
|
my ($type, $cond) = ('inner',); |
17
|
10
|
|
|
|
|
18
|
my $ref = ref $join_cond; |
18
|
10
|
100
|
100
|
|
|
49
|
if (!$ref || $ref eq 'HASH') { |
|
|
50
|
|
|
|
|
|
19
|
3
|
|
|
|
|
5
|
$cond = $join_cond; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
22
|
7
|
100
|
|
|
|
38
|
if (uc($join_cond->[0]) =~ /^(?:(?:(?:LEFT|RIGHT|FULL)(?: OUTER)?)|INNER|CROSS)$/) { |
23
|
5
|
|
|
|
|
9
|
$type = $join_cond->[0]; |
24
|
5
|
|
|
|
|
5
|
$cond = $join_cond->[1]; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
2
|
|
|
|
|
5
|
$cond = $join_cond; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
0
|
|
|
|
|
0
|
Carp::croak 'join condition is not valid'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
61
|
push @joins, [$base_table => { |
35
|
|
|
|
|
|
|
type => $type, |
36
|
|
|
|
|
|
|
table => $table, |
37
|
|
|
|
|
|
|
condition => $cond, |
38
|
|
|
|
|
|
|
}]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
8
|
50
|
|
|
|
9
|
my %opt = %{ $opt || {} }; |
|
8
|
|
|
|
|
40
|
|
42
|
8
|
|
|
|
|
13
|
push @{ $opt{joins} }, @joins; |
|
8
|
|
|
|
|
18
|
|
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
35
|
$self->select(undef, $fields, $where, \%opt); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
__END__ |