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   6224 use v5.26;
  5         18  
5 5     5   22 use strict;
  5         11  
  5         116  
6 5     5   19 use warnings;
  5         11  
  5         279  
7 5     5   21 use warnings qw( FATAL utf8 );
  5         322  
  5         237  
8 5     5   27 use utf8;
  5         9  
  5         30  
9 5     5   127 use open qw( :std :utf8 );
  5         8  
  5         33  
10 5     5   664 use Unicode::Normalize qw( NFC );
  5         7  
  5         248  
11 5     5   23 use Unicode::Collate;
  5         7  
  5         163  
12 5     5   20 use Encode qw( decode );
  5         9  
  5         678  
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   28 use autodie;
  5         9  
  5         51  
24 5     5   25170 use Carp qw( carp croak confess cluck );
  5         7  
  5         412  
25 5     5   30 use English qw( -no_match_vars );
  5         10  
  5         36  
26 5     5   1852 use Data::Dumper qw( Dumper );
  5         10  
  5         1030  
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   32 use parent qw( Pg::SQL::PrettyPrinter::Node );
  5         9  
  5         39  
44              
45             sub new {
46 15     15 1 303 my $class = shift;
47 15         54 my $self = $class->SUPER::new( @_ );
48 15         24 bless $self, $class;
49              
50 15         52 $self->objectify( 'args' );
51              
52 15         29 return $self;
53             }
54              
55             sub as_text {
56 21     21 1 30 my $self = shift;
57 21         30 return sprintf( '( %s )', join( ', ', map { $_->as_text } @{ $self->{ 'args' } } ) );
  46         82  
  21         36  
58             }
59              
60             sub pretty_print {
61 9     9 1 15 my $self = shift;
62 9         24 my $text = $self->as_text;
63 9 100       44 return $text if length( $text ) < 40;
64 1         2 my @lines = ();
65 1         2 push @lines, '(';
66 1         2 push @lines, map { $self->increase_indent( $_->pretty_print ) . ',' } @{ $self->{ 'args' } };
  2         6  
  1         2  
67 1         4 $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: