File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/RangeVar.pm
Criterion Covered Total %
statement 55 58 94.8
branch 3 4 75.0
condition n/a
subroutine 16 16 100.0
pod 2 2 100.0
total 76 80 95.0


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::RangeVar;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 8     8   8434 use v5.26;
  8         31  
5 8     8   46 use strict;
  8         18  
  8         246  
6 8     8   96 use warnings;
  8         15  
  8         469  
7 8     8   37 use warnings qw( FATAL utf8 );
  8         14  
  8         399  
8 8     8   41 use utf8;
  8         14  
  8         50  
9 8     8   289 use open qw( :std :utf8 );
  8         16  
  8         49  
10 8     8   1207 use Unicode::Normalize qw( NFC );
  8         15  
  8         588  
11 8     8   47 use Unicode::Collate;
  8         23  
  8         241  
12 8     8   43 use Encode qw( decode );
  8         20  
  8         1237  
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 8     8   53 use autodie;
  8         18  
  8         55  
24 8     8   42269 use Carp qw( carp croak confess cluck );
  8         18  
  8         789  
25 8     8   53 use English qw( -no_match_vars );
  8         15  
  8         60  
26 8     8   3145 use Data::Dumper qw( Dumper );
  8         15  
  8         1815  
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 8     8   54 use parent qw( Pg::SQL::PrettyPrinter::Node );
  8         13  
  8         62  
44              
45             sub new {
46 75     75 1 2510 my $class = shift;
47 75         378 my $self = $class->SUPER::new( @_ );
48 75         157 bless $self, $class;
49              
50 75         393 $self->objectify( [ 'alias', 'colnames' ] );
51              
52 75         277 return $self;
53             }
54              
55             sub as_text {
56 148     148 1 266 my $self = shift;
57 148         534 my @elements = map { $self->quote_ident( $self->{ $_ } ) }
58 148         289 grep { exists $self->{ $_ } } qw{ catalogname schemaname relname };
  444         1048  
59 148         356 my $full_name = join( '.', @elements );
60              
61             # Shortcut
62 148         286 my $A = $self->{ 'alias' };
63 148 100       677 return $full_name unless $A;
64              
65 30         99 my $base_with_alias = sprintf( '%s AS %s', $full_name, $self->quote_ident( $A->{ 'aliasname' } ) );
66 30 50       194 return $base_with_alias unless $A->{ 'colnames' };
67              
68 0           return sprintf( '%s ( %s )', $base_with_alias, join( ', ', map { $_->as_ident } @{ $A->{ 'colnames' } } ) );
  0            
  0            
69             }
70              
71             1;