File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/RowExpr.pm
Criterion Covered Total %
statement 61 61 100.0
branch 2 2 100.0
condition n/a
subroutine 17 17 100.0
pod 2 3 66.6
total 82 83 98.8


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::RowExpr;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 4     4   2746 use v5.26;
  4         19  
5 4     4   26 use strict;
  4         13  
  4         94  
6 4     4   17 use warnings;
  4         17  
  4         115  
7 4     4   27 use warnings qw( FATAL utf8 );
  4         9  
  4         130  
8 4     4   26 use utf8;
  4         14  
  4         21  
9 4     4   135 use open qw( :std :utf8 );
  4         9  
  4         30  
10 4     4   551 use Unicode::Normalize qw( NFC );
  4         30  
  4         258  
11 4     4   35 use Unicode::Collate;
  4         11  
  4         158  
12 4     4   25 use Encode qw( decode );
  4         17  
  4         269  
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 4     4   917 use autodie;
  4         13  
  4         36  
24 4     4   23054 use Carp qw( carp croak confess cluck );
  4         26  
  4         374  
25 4     4   44 use English qw( -no_match_vars );
  4         13  
  4         42  
26 4     4   1567 use Data::Dumper qw( Dumper );
  4         12  
  4         892  
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 4     4   37 use parent qw( Pg::SQL::PrettyPrinter::Node );
  4         23  
  4         38  
44              
45             sub new {
46 15     15 1 391 my $class = shift;
47 15         66 my $self = $class->SUPER::new( @_ );
48 15         29 bless $self, $class;
49              
50 15         64 $self->objectify( 'args' );
51              
52 15         35 return $self;
53             }
54              
55             sub as_text {
56 21     21 0 36 my $self = shift;
57 21         32 return sprintf( '( %s )', join( ', ', map { $_->as_text } @{ $self->{ 'args' } } ) );
  46         116  
  21         46  
58             }
59              
60             sub pretty_print {
61 9     9 1 22 my $self = shift;
62 9         108 my $text = $self->as_text;
63 9 100       62 return $text if length( $text ) < 40;
64 1         2 my @lines = ();
65 1         3 push @lines, '(';
66 1         2 push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'args' } };
  2         13  
  1         2  
67 1         6 $lines[ -1 ] =~ s/,\z//;
68 1         3 push @lines, ')';
69 1         5 return join( "\n", @lines );
70             }
71              
72             1;
73              
74             # vim: set ft=perl: