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
|
|
2184
|
use v5.26; |
|
3
|
|
|
|
|
117
|
|
5
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
88
|
|
|
3
|
|
|
|
|
77
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
7
|
3
|
|
|
3
|
|
26
|
use warnings qw( FATAL utf8 ); |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
103
|
|
8
|
3
|
|
|
3
|
|
15
|
use utf8; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
27
|
|
9
|
3
|
|
|
3
|
|
106
|
use open qw( :std :utf8 ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
17
|
|
10
|
3
|
|
|
3
|
|
455
|
use Unicode::Normalize qw( NFC ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
196
|
|
11
|
3
|
|
|
3
|
|
22
|
use Unicode::Collate; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
126
|
|
12
|
3
|
|
|
3
|
|
17
|
use Encode qw( decode ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
183
|
|
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
|
|
679
|
use autodie; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
21
|
|
24
|
3
|
|
|
3
|
|
16672
|
use Carp qw( carp croak confess cluck ); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
275
|
|
25
|
3
|
|
|
3
|
|
30
|
use English qw( -no_match_vars ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
20
|
|
26
|
3
|
|
|
3
|
|
1187
|
use Data::Dumper qw( Dumper ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
713
|
|
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
|
|
32
|
use parent qw( Pg::SQL::PrettyPrinter::Node ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
23
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
10
|
|
|
10
|
1
|
276
|
my $class = shift; |
47
|
10
|
|
|
|
|
42
|
my $self = $class->SUPER::new( @_ ); |
48
|
10
|
|
|
|
|
24
|
bless $self, $class; |
49
|
10
|
|
|
|
|
32
|
my @known_types_array = qw( ALL_SUBLINK ANY_SUBLINK EXPR_SUBLINK ARRAY_SUBLINK EXISTS_SUBLINK ); |
50
|
10
|
|
|
|
|
17
|
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
|
|
|
|
|
45
|
@known_types{ @known_types_array } = @known_types_array; |
54
|
|
|
|
|
|
|
|
55
|
10
|
50
|
|
|
|
42
|
croak( 'Unknown subselect type: ' . $self->{ 'subLinkType' } ) unless exists $known_types{ $self->{ 'subLinkType' } }; |
56
|
|
|
|
|
|
|
|
57
|
10
|
|
|
|
|
43
|
$self->objectify( 'subselect' ); |
58
|
10
|
100
|
|
|
|
49
|
if ( $self->{ 'subLinkType' } =~ m{\A(?:ALL|ANY)_SUBLINK\z} ) { |
59
|
3
|
|
|
|
|
14
|
$self->objectify( 'testexpr', 'operName' ); |
60
|
|
|
|
|
|
|
} |
61
|
10
|
100
|
|
|
|
26
|
if ( exists $self->{ 'operName' } ) { |
62
|
2
|
50
|
|
|
|
5
|
croak( "Can't handle operName with more than 1 element: " . Dumper( $self ) ) if 1 != scalar @{ $self->{ 'operName' } }; |
|
2
|
|
|
|
|
7
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
10
|
|
|
|
|
41
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub as_text { |
69
|
9
|
|
|
9
|
1
|
19
|
my $self = shift; |
70
|
9
|
|
|
|
|
33
|
my $subselect_text = $self->{ 'subselect' }->as_text; |
71
|
|
|
|
|
|
|
|
72
|
9
|
100
|
|
|
|
57
|
if ( $self->{ 'subLinkType' } =~ m{\A(ANY|ALL)_SUBLINK\z} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
73
|
3
|
|
|
|
|
10
|
my $type = $1; |
74
|
3
|
100
|
|
|
|
10
|
if ( exists $self->{ 'operName' } ) { |
75
|
2
|
|
|
|
|
6
|
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
|
|
|
|
|
3
|
return sprintf( '%s IN ( %s )', $self->{ 'testexpr' }->as_text, $subselect_text ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'ARRAY_SUBLINK' ) { |
83
|
1
|
|
|
|
|
4
|
return sprintf( 'ARRAY( %s )', $subselect_text ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ( $self->{ 'subLinkType' } eq 'EXISTS_SUBLINK' ) { |
86
|
1
|
|
|
|
|
5
|
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
|
14
|
my $self = shift; |
93
|
8
|
|
|
|
|
33
|
my $subselect_text = $self->increase_indent( $self->{ 'subselect' }->pretty_print ); |
94
|
|
|
|
|
|
|
|
95
|
8
|
|
|
|
|
25
|
my @lines = (); |
96
|
8
|
100
|
|
|
|
78
|
if ( $self->{ 'subLinkType' } =~ m{\A(ANY|ALL)_SUBLINK\z} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
97
|
3
|
|
|
|
|
9
|
my $type = $1; |
98
|
3
|
100
|
|
|
|
10
|
if ( exists $self->{ 'operName' } ) { |
99
|
2
|
|
|
|
|
5
|
my $opname = $self->{ 'operName' }->[ 0 ]->{ 'str' }; |
100
|
2
|
|
|
|
|
8
|
push @lines, sprintf( '%s %s %s(', $self->{ 'testexpr' }->pretty_print, $opname, $type ); |
101
|
2
|
|
|
|
|
7
|
push @lines, $subselect_text; |
102
|
2
|
|
|
|
|
4
|
push @lines, ')'; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
1
|
|
|
|
|
6
|
push @lines, $self->{ 'testexpr' }->pretty_print . ' IN ('; |
106
|
1
|
|
|
|
|
3
|
push @lines, $subselect_text; |
107
|
1
|
|
|
|
|
5
|
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
|
|
|
|
|
10
|
push @lines, '('; |
122
|
3
|
|
|
|
|
8
|
push @lines, $subselect_text; |
123
|
3
|
|
|
|
|
8
|
push @lines, ')'; |
124
|
|
|
|
|
|
|
} |
125
|
8
|
|
|
|
|
38
|
return join( "\n", @lines ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |