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 3 3 100.0
total 83 83 100.0


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 5     5   6981 use v5.26;
  5         24  
5 5     5   29 use strict;
  5         21  
  5         150  
6 5     5   26 use warnings;
  5         9  
  5         308  
7 5     5   27 use warnings qw( FATAL utf8 );
  5         245  
  5         291  
8 5     5   28 use utf8;
  5         11  
  5         35  
9 5     5   215 use open qw( :std :utf8 );
  5         10  
  5         36  
10 5     5   790 use Unicode::Normalize qw( NFC );
  5         10  
  5         323  
11 5     5   32 use Unicode::Collate;
  5         10  
  5         234  
12 5     5   30 use Encode qw( decode );
  5         13  
  5         885  
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 5     5   36 use autodie;
  5         12  
  5         42  
24 5     5   29779 use Carp qw( carp croak confess cluck );
  5         13  
  5         519  
25 5     5   39 use English qw( -no_match_vars );
  5         12  
  5         47  
26 5     5   2127 use Data::Dumper qw( Dumper );
  5         13  
  5         1389  
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 5     5   40 use parent qw( Pg::SQL::PrettyPrinter::Node );
  5         11  
  5         42  
44              
45             sub new {
46 15     15 1 288 my $class = shift;
47 15         48 my $self = $class->SUPER::new( @_ );
48 15         25 bless $self, $class;
49              
50 15         50 $self->objectify( 'args' );
51              
52 15         28 return $self;
53             }
54              
55             sub as_text {
56 21     21 1 30 my $self = shift;
57 21         28 return sprintf( '( %s )', join( ', ', map { $_->as_text } @{ $self->{ 'args' } } ) );
  46         79  
  21         33  
58             }
59              
60             sub pretty_print {
61 9     9 1 13 my $self = shift;
62 9         21 my $text = $self->as_text;
63 9 100       54 return $text if length( $text ) < 40;
64 1         2 my @lines = ();
65 1         3 push @lines, '(';
66 1         1 push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'args' } };
  2         6  
  1         3  
67 1         3 $lines[ -1 ] =~ s/,\z//;
68 1         2 push @lines, ')';
69 1         4 return join( "\n", @lines );
70             }
71              
72             1;
73              
74             # vim: set ft=perl: