File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/CommonTableExpr.pm
Criterion Covered Total %
statement 65 65 100.0
branch 6 6 100.0
condition n/a
subroutine 18 18 100.0
pod 4 4 100.0
total 93 93 100.0


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::CommonTableExpr;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 6     6   8172 use v5.26;
  6         27  
5 6     6   46 use strict;
  6         15  
  6         176  
6 6     6   30 use warnings;
  6         15  
  6         544  
7 6     6   40 use warnings qw( FATAL utf8 );
  6         12  
  6         438  
8 6     6   38 use utf8;
  6         15  
  6         52  
9 6     6   254 use open qw( :std :utf8 );
  6         12  
  6         49  
10 6     6   1208 use Unicode::Normalize qw( NFC );
  6         16  
  6         490  
11 6     6   80 use Unicode::Collate;
  6         11  
  6         253  
12 6     6   35 use Encode qw( decode );
  6         39  
  6         1119  
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 6     6   3537 use autodie;
  6         17  
  6         63  
24 6     6   46960 use Carp qw( carp croak confess cluck );
  6         18  
  6         882  
25 6     6   51 use English qw( -no_match_vars );
  6         13  
  6         100  
26 6     6   4176 use Data::Dumper qw( Dumper );
  6         17  
  6         2118  
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 6     6   81 use parent qw( Pg::SQL::PrettyPrinter::Node );
  6         17  
  6         62  
44              
45             sub new {
46 7     7 1 142 my $class = shift;
47 7         51 my $self = $class->SUPER::new( @_ );
48 7         17 bless $self, $class;
49              
50 7         44 $self->objectify( qw( ctequery aliascolnames ) );
51              
52 7         19 return $self;
53             }
54              
55             sub as_text {
56 7     7 1 14 my $self = shift;
57             return join(
58             ' ',
59             $self->header,
60 7         30 $self->{ 'ctequery' }->as_text,
61             ')'
62             );
63             }
64              
65             sub pretty_print {
66 7     7 1 14 my $self = shift;
67             return join(
68             "\n",
69             $self->header,
70 7         21 $self->increase_indent( $self->{ 'ctequery' }->pretty_print ),
71             ')'
72             );
73             }
74              
75             sub header {
76 14     14 1 27 my $self = shift;
77 14 100       81 return $self->{ '_header' } if $self->{ '_header' };
78              
79 7         16 my @header = ();
80 7         40 push @header, $self->quote_ident( $self->{ 'ctename' } );
81 7 100       26 if ( exists $self->{ 'aliascolnames' } ) {
82 1         3 push @header, '(';
83 1         2 push @header, join( ', ', map { $_->as_ident } @{ $self->{ 'aliascolnames' } } );
  2         7  
  1         3  
84 1         3 push @header, ')';
85             }
86 7         18 push @header, 'AS';
87 7 100       21 push @header, 'MATERIALIZED' if $self->{ 'ctematerialized' } eq 'CTEMaterializeAlways';
88 7         17 push @header, '(';
89 7         24 $self->{ '_header' } = join( ' ', @header );
90 7         32 return $self->{ '_header' };
91             }
92             1;
93              
94             # vim: set ft=perl: