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   7285 use v5.26;
  6         23  
5 6     6   30 use strict;
  6         11  
  6         137  
6 6     6   22 use warnings;
  6         10  
  6         376  
7 6     6   28 use warnings qw( FATAL utf8 );
  6         11  
  6         363  
8 6     6   30 use utf8;
  6         12  
  6         36  
9 6     6   193 use open qw( :std :utf8 );
  6         10  
  6         40  
10 6     6   913 use Unicode::Normalize qw( NFC );
  6         11  
  6         350  
11 6     6   31 use Unicode::Collate;
  6         11  
  6         200  
12 6     6   28 use Encode qw( decode );
  6         10  
  6         835  
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   70 use autodie;
  6         11  
  6         49  
24 6     6   24521 use Carp qw( carp croak confess cluck );
  6         9  
  6         439  
25 6     6   27 use English qw( -no_match_vars );
  6         10  
  6         41  
26 6     6   2165 use Data::Dumper qw( Dumper );
  6         12  
  6         1351  
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   44 use parent qw( Pg::SQL::PrettyPrinter::Node );
  6         11  
  6         48  
44              
45             sub new {
46 7     7 1 124 my $class = shift;
47 7         66 my $self = $class->SUPER::new( @_ );
48 7         11 bless $self, $class;
49              
50 7         26 $self->objectify( qw( ctequery aliascolnames ) );
51              
52 7         14 return $self;
53             }
54              
55             sub as_text {
56 7     7 1 10 my $self = shift;
57             return join(
58             ' ',
59             $self->header,
60 7         18 $self->{ 'ctequery' }->as_text,
61             ')'
62             );
63             }
64              
65             sub pretty_print {
66 7     7 1 13 my $self = shift;
67             return join(
68             "\n",
69             $self->header,
70 7         17 $self->increase_indent( $self->{ 'ctequery' }->pretty_print ),
71             ')'
72             );
73             }
74              
75             sub header {
76 14     14 1 18 my $self = shift;
77 14 100       43 return $self->{ '_header' } if $self->{ '_header' };
78              
79 7         12 my @header = ();
80 7         24 push @header, $self->quote_ident( $self->{ 'ctename' } );
81 7 100       17 if ( exists $self->{ 'aliascolnames' } ) {
82 1         2 push @header, '(';
83 1         2 push @header, join( ', ', map { $_->as_ident } @{ $self->{ 'aliascolnames' } } );
  2         6  
  1         2  
84 1         4 push @header, ')';
85             }
86 7         12 push @header, 'AS';
87 7 100       18 push @header, 'MATERIALIZED' if $self->{ 'ctematerialized' } eq 'CTEMaterializeAlways';
88 7         14 push @header, '(';
89 7         20 $self->{ '_header' } = join( ' ', @header );
90 7         23 return $self->{ '_header' };
91             }
92             1;
93              
94             # vim: set ft=perl: