| 1 | package Pg::SQL::PrettyPrinter::Node::ResTarget; | ||||||||||||
| 2 | |||||||||||||
| 3 | # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/ | ||||||||||||
| 4 | 11 | ▶ | use v5.26; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 11 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 11 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 11 | ▶ | use warnings qw( FATAL utf8 ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 11 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 11 | ▶ | use open qw( :std :utf8 ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 11 | ▶ | use Unicode::Normalize qw( NFC ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 11 | ▶ | use Unicode::Collate; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 11 | ▶ | use Encode qw( decode ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 11 | ▶ | if ( grep /\P{ASCII}/ => @ARGV ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | 0 | @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 | 11 | ▶ | use autodie; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 11 | ▶ | use Carp qw( carp croak confess cluck ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 11 | ▶ | use English qw( -no_match_vars ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 11 | ▶ | use Data::Dumper qw( Dumper ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | # give a full stack dump on any untrapped exceptions | ||||||||||||
| 29 | 0 | ▶ | local $SIG{ __DIE__ } = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 30 | 0 | ▶ | confess "Uncaught exception: @_" unless $^S; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 11 | }; | |||||||||||
| 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 | 0 | ▶ | local $SIG{ __WARN__ } = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 37 | 0 | ▶ | if ( $^S ) { cluck "Trapped warning: @_" } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 0 | else { confess "Deadly warning: @_" } | |||||||||||
| 39 | 11 | }; | |||||||||||
| 40 | |||||||||||||
| 41 | # Useful common code | ||||||||||||
| 42 | |||||||||||||
| 43 | 11 | ▶ | use parent qw( Pg::SQL::PrettyPrinter::Node ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | |||||||||||||
| 45 | 326 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 46 | 326 | my $class = shift; | |||||||||||
| 47 | 326 | my $self = $class->SUPER::new( @_ ); | |||||||||||
| 48 | 326 | bless $self, $class; | |||||||||||
| 49 | |||||||||||||
| 50 | 326 | $self->objectify( 'val' ); | |||||||||||
| 51 | 326 | return $self; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 345 | ▶ | sub as_text { | ||||||||||
|
Subroutine
as_text: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||
| 55 | 345 | my $self = shift; | |||||||||||
| 56 | 345 | ▶ | my $mode = shift || 'select'; | ||||||||||
|
Condition50%1/2
shift() || 'select'
MC/DC0%0/1
shift() || 'select'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 57 | |||||||||||||
| 58 | 345 | my $val; | |||||||||||
| 59 | 345 | ▶ | if ( $mode eq 'assignment' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 0 | $val = $self->quote_ident( $self->{ 'name' } ) . ' = ' . $self->{ 'val' }->as_text; | |||||||||||
| 61 | } | ||||||||||||
| 62 | else { | ||||||||||||
| 63 | 345 | ▶ | if ( exists $self->{ 'val' } ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | 265 | $val = $self->{ 'val' }->as_text(); | |||||||||||
| 65 | 265 | ▶ | if ( exists( $self->{ 'name' } ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 18 | $val .= ' AS ' . $self->quote_ident( $self->{ 'name' } ); | |||||||||||
| 67 | } | ||||||||||||
| 68 | } | ||||||||||||
| 69 | else { | ||||||||||||
| 70 | 80 | $val = $self->quote_ident( $self->{ 'name' } ); | |||||||||||
| 71 | } | ||||||||||||
| 72 | } | ||||||||||||
| 73 | 345 | return $val; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 248 | ▶ | sub pretty_print { | ||||||||||
|
Subroutine
pretty_print: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||
| 77 | 248 | my $self = shift; | |||||||||||
| 78 | 248 | ▶ | my $mode = shift || 'select'; | ||||||||||
|
Condition50%1/2
shift() || 'select'
MC/DC0%0/1
shift() || 'select'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 79 | |||||||||||||
| 80 | 248 | my $val; | |||||||||||
| 81 | 248 | ▶ | if ( $mode eq 'assignment' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | $val = $self->quote_ident( $self->{ 'name' } ) . ' = ' . $self->{ 'val' }->pretty_print; | |||||||||||
| 83 | } | ||||||||||||
| 84 | else { | ||||||||||||
| 85 | 248 | ▶ | if ( exists $self->{ 'val' } ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 248 | $val = $self->{ 'val' }->pretty_print(); | |||||||||||
| 87 | 248 | ▶ | if ( exists( $self->{ 'name' } ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | 18 | $val .= ' AS ' . $self->quote_ident( $self->{ 'name' } ); | |||||||||||
| 89 | } | ||||||||||||
| 90 | } | ||||||||||||
| 91 | else { | ||||||||||||
| 92 | 0 | $val = $self->quote_ident( $self->{ 'name' } ); | |||||||||||
| 93 | } | ||||||||||||
| 94 | } | ||||||||||||
| 95 | 248 | return $val; | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 11 | 1; | |||||||||||