line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pg::SQL::PrettyPrinter::Node::TypeCast; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ |
4
|
3
|
|
|
3
|
|
2157
|
use v5.26; |
|
3
|
|
|
|
|
13
|
|
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
69
|
|
6
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
90
|
|
7
|
3
|
|
|
3
|
|
16
|
use warnings qw( FATAL utf8 ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
91
|
|
8
|
3
|
|
|
3
|
|
17
|
use utf8; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
19
|
|
9
|
3
|
|
|
3
|
|
101
|
use open qw( :std :utf8 ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
15
|
|
10
|
3
|
|
|
3
|
|
411
|
use Unicode::Normalize qw( NFC ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
163
|
|
11
|
3
|
|
|
3
|
|
21
|
use Unicode::Collate; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
103
|
|
12
|
3
|
|
|
3
|
|
17
|
use Encode qw( decode ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
169
|
|
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
|
|
680
|
use autodie; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
49
|
|
24
|
3
|
|
|
3
|
|
16513
|
use Carp qw( carp croak confess cluck ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
252
|
|
25
|
3
|
|
|
3
|
|
20
|
use English qw( -no_match_vars ); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
25
|
|
26
|
3
|
|
|
3
|
|
1138
|
use Data::Dumper qw( Dumper ); |
|
3
|
|
|
|
|
8
|
|
|
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
|
|
22
|
use parent qw( Pg::SQL::PrettyPrinter::Node ); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
23
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
33
|
|
|
33
|
1
|
1083
|
my $class = shift; |
47
|
33
|
|
|
|
|
122
|
my $self = $class->SUPER::new( @_ ); |
48
|
33
|
|
|
|
|
88
|
bless $self, $class; |
49
|
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
172
|
$self->objectify( |
51
|
|
|
|
|
|
|
'arg', |
52
|
|
|
|
|
|
|
[ 'typeName', 'names' ], |
53
|
|
|
|
|
|
|
[ 'typeName', 'typmods' ], |
54
|
|
|
|
|
|
|
[ 'typeName', 'arrayBounds' ] |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
33
|
|
|
|
|
104
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub as_text { |
61
|
62
|
|
|
62
|
1
|
103
|
my $self = shift; |
62
|
62
|
|
|
|
|
171
|
my $arg = $self->{ 'arg' }->as_text; |
63
|
62
|
50
|
|
|
|
298
|
if ( ref( $self->{ 'arg' } ) =~ m{\APg::SQL::PrettyPrinter::Node::(?:A_|Bool)Expr\z} ) { |
64
|
0
|
|
|
|
|
0
|
$arg = "( $arg )"; |
65
|
|
|
|
|
|
|
} |
66
|
62
|
|
|
|
|
112
|
my $typname = join( '.', map { $_->as_ident } @{ $self->{ 'typeName' }->{ 'names' } } ); |
|
90
|
|
|
|
|
249
|
|
|
62
|
|
|
|
|
154
|
|
67
|
|
|
|
|
|
|
|
68
|
62
|
100
|
|
|
|
175
|
if ( $typname eq 'pg_catalog.bool' ) { |
69
|
24
|
100
|
|
|
|
71
|
return 'true' if $arg eq "'t'"; |
70
|
14
|
100
|
|
|
|
33
|
return 'false' if $arg eq "'f'"; |
71
|
|
|
|
|
|
|
} |
72
|
50
|
|
|
|
|
89
|
my $typmods = ''; |
73
|
50
|
100
|
|
|
|
130
|
if ( exists $self->{ 'typeName' }->{ 'typmods' } ) { |
74
|
2
|
|
|
|
|
5
|
$typmods = '( ' . join( ', ', map { $_->as_text } @{ $self->{ 'typeName' }->{ 'typmods' } } ) . ' )'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
5
|
|
75
|
|
|
|
|
|
|
} |
76
|
50
|
100
|
|
|
|
120
|
if ( exists $self->{ 'typeName' }->{ 'arrayBounds' } ) { |
77
|
12
|
|
|
|
|
22
|
my @bounds_as_text = map { $_->as_text } @{ $self->{ 'typeName' }->{ 'arrayBounds' } }; |
|
12
|
|
|
|
|
40
|
|
|
12
|
|
|
|
|
31
|
|
78
|
12
|
|
|
|
|
58
|
my $array_def = sprintf '[%s]', join( ', ', @bounds_as_text ); |
79
|
12
|
50
|
|
|
|
38
|
$array_def = '[]' if $array_def eq '[-1]'; |
80
|
12
|
|
|
|
|
25
|
$typmods .= $array_def; |
81
|
|
|
|
|
|
|
} |
82
|
50
|
|
|
|
|
249
|
return sprintf '%s::%s%s', $arg, $typname, $typmods; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |