line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pg::SQL::PrettyPrinter::Node::SubLink; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
4
|
3
|
|
|
3
|
|
2086
|
use v5.26; |
|
3
|
|
|
|
|
93
|
|
5
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
93
|
|
|
3
|
|
|
|
|
80
|
|
6
|
3
|
|
|
3
|
|
25
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
87
|
|
7
|
3
|
|
|
3
|
|
17
|
use warnings qw( FATAL utf8 ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
87
|
|
8
|
3
|
|
|
3
|
|
16
|
use utf8; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
37
|
|
9
|
3
|
|
|
3
|
|
82
|
use open qw( :std :utf8 ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
15
|
|
10
|
3
|
|
|
3
|
|
405
|
use Unicode::Normalize qw( NFC ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
166
|
|
11
|
3
|
|
|
3
|
|
22
|
use Unicode::Collate; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
95
|
|
12
|
3
|
|
|
3
|
|
17
|
use Encode qw( decode ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
179
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
if ( grep /\P{ASCII}/ => @ARGV ) { |
15
|
|
|
|
|
|
|
@ARGV = map { decode( 'UTF-8', $_ ) } @ARGV; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# If there is __DATA__,then uncomment next line: |
19
|
|
|
|
|
|
|
# binmode( DATA, ':encoding(UTF-8)' ); |
20
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Useful common code |
23
|
3
|
|
|
3
|
|
661
|
use autodie; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
19
|
|
24
|
3
|
|
|
3
|
|
16432
|
use Carp qw( carp croak confess cluck ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
269
|
|
25
|
3
|
|
|
3
|
|
23
|
use English qw( -no_match_vars ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
30
|
|
26
|
3
|
|
|
3
|
|
1180
|
use Data::Dumper qw( Dumper ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
661
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# give a full stack dump on any untrapped exceptions |
29
|
|
|
|
|
|
|
local $SIG{ __DIE__ } = sub { |
30
|
|
|
|
|
|
|
confess "Uncaught exception: @_" unless $^S; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# now promote run-time warnings into stackdumped exceptions |
34
|
|
|
|
|
|
|
# *unless* we're in an try block, in which |
35
|
|
|
|
|
|
|
# case just generate a clucking stackdump instead |
36
|
|
|
|
|
|
|
local $SIG{ __WARN__ } = sub { |
37
|
|
|
|
|
|
|
if ( $^S ) { cluck "Trapped warning: @_" } |
38
|
|
|
|
|
|
|
else { confess "Deadly warning: @_" } |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Useful common code |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
3
|
|
24
|
use parent qw( Pg::SQL::PrettyPrinter::Node ); |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
20
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
10
|
|
|
10
|
1
|
282
|
my $class = shift; |
47
|
10
|
|
|
|
|
39
|
my $self = $class->SUPER::new( @_ ); |
48
|
10
|
|
|
|
|
19
|
bless $self, $class; |
49
|
10
|
|
|
|
|
27
|
my @known_types_array = qw( ALL_SUBLINK ANY_SUBLINK EXPR_SUBLINK ARRAY_SUBLINK EXISTS_SUBLINK ); |
50
|
10
|
|
|
|
|
20
|
my %known_types; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Builds %known_types, where each key is elements form @known_types_array, and the value is the same as key. |
53
|
10
|
|
|
|
|
47
|
@known_types{ @known_types_array } = @known_types_array; |
54
|
|
|
|
|
|
|
|
55
|
10
|
50
|
|
|
|
39
|
croak( 'Unknown subselect type: ' . $self->{ 'subLinkType' } ) unless exists $known_types{ $self->{ 'subLinkType' } }; |
56
|
|
|
|
|
|
|
|
57
|
10
|
|
|
|
|
45
|
$self->objectify( 'subselect' ); |
58
|
10
|
100
|
|
|
|
45
|
if ( $self->{ 'subLinkType' } =~ m{\A(?:ALL|ANY)_SUBLINK\z} ) { |
59
|
3
|
|
|
|
|
12
|
$self->objectify( 'testexpr', 'operName' ); |
60
|
|
|
|
|
|
|
} |
61
|
10
|
100
|
|
|
|
27
|
if ( exists $self->{ 'operName' } ) { |
62
|
2
|
50
|
|
|
|
3
|
croak( "Can't handle operName with more than 1 element: " . Dumper( $self ) ) if 1 != scalar @{ $self->{ 'operName' } }; |
|
2
|
|
|
|
|
8
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
10
|
|
|
|
|
42
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub as_text { |
69
|
9
|
|
|
9
|
1
|
20
|
my $self = shift; |
70
|
9
|
|
|
|
|
29
|
my $subselect_text = $self->{ 'subselect' }->as_text; |
71
|
|
|
|
|
|
|
|
72
|
9
|
100
|
|
|
|
49
|
if ( $self->{ 'subLinkType' } =~ m{\A(ANY|ALL)_SUBLINK\z} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
73
|
3
|
|
|
|
|
12
|
my $type = $1; |
74
|
3
|
100
|
|
|
|
10
|
if ( exists $self->{ 'operName' } ) { |
75
|
2
|
|
|
|
|
7
|
my $opname = $self->{ 'operName' }->[ 0 ]->{ 'str' }; |
76
|
2
|
|
|
|
|
9
|
return sprintf( '%s %s %s( %s )', $self->{ 'testexpr' }->as_text, $opname, $type, $subselect_text ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
1
|
|
|
|
|
6
|
return sprintf( '%s IN ( %s )', $self->{ 'testexpr' }->as_text, $subselect_text ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'ARRAY_SUBLINK' ) { |
83
|
1
|
|
|
|
|
6
|
return sprintf( 'ARRAY( %s )', $subselect_text ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'EXISTS_SUBLINK' ) { |
86
|
1
|
|
|
|
|
4
|
return sprintf( 'EXISTS ( %s )', $subselect_text ); |
87
|
|
|
|
|
|
|
} |
88
|
4
|
|
|
|
|
17
|
return sprintf( '( %s )', $self->{ 'subselect' }->as_text ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub pretty_print { |
92
|
8
|
|
|
8
|
1
|
17
|
my $self = shift; |
93
|
8
|
|
|
|
|
30
|
my $subselect_text = $self->increase_indent( $self->{ 'subselect' }->pretty_print ); |
94
|
|
|
|
|
|
|
|
95
|
8
|
|
|
|
|
17
|
my @lines = (); |
96
|
8
|
100
|
|
|
|
46
|
if ( $self->{ 'subLinkType' } =~ m{\A(ANY|ALL)_SUBLINK\z} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
97
|
3
|
|
|
|
|
10
|
my $type = $1; |
98
|
3
|
100
|
|
|
|
9
|
if ( exists $self->{ 'operName' } ) { |
99
|
2
|
|
|
|
|
6
|
my $opname = $self->{ 'operName' }->[ 0 ]->{ 'str' }; |
100
|
2
|
|
|
|
|
8
|
push @lines, sprintf( '%s %s %s(', $self->{ 'testexpr' }->pretty_print, $opname, $type ); |
101
|
2
|
|
|
|
|
6
|
push @lines, $subselect_text; |
102
|
2
|
|
|
|
|
5
|
push @lines, ')'; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
1
|
|
|
|
|
4
|
push @lines, $self->{ 'testexpr' }->pretty_print . ' IN ('; |
106
|
1
|
|
|
|
|
7
|
push @lines, $subselect_text; |
107
|
1
|
|
|
|
|
2
|
push @lines, ')'; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'ARRAY_SUBLINK' ) { |
111
|
1
|
|
|
|
|
3
|
push @lines, 'ARRAY('; |
112
|
1
|
|
|
|
|
2
|
push @lines, $subselect_text; |
113
|
1
|
|
|
|
|
2
|
push @lines, ')'; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'EXISTS_SUBLINK' ) { |
116
|
1
|
|
|
|
|
3
|
push @lines, 'EXISTS ('; |
117
|
1
|
|
|
|
|
2
|
push @lines, $subselect_text; |
118
|
1
|
|
|
|
|
2
|
push @lines, ')'; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
3
|
|
|
|
|
8
|
push @lines, '('; |
122
|
3
|
|
|
|
|
7
|
push @lines, $subselect_text; |
123
|
3
|
|
|
|
|
6
|
push @lines, ')'; |
124
|
|
|
|
|
|
|
} |
125
|
8
|
|
|
|
|
36
|
return join( "\n", @lines ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |