File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/A_Const.pm
Criterion Covered Total %
statement 62 66 93.9
branch 12 20 60.0
condition 4 8 50.0
subroutine 17 17 100.0
pod 3 3 100.0
total 98 114 85.9


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::A_Const;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 12     12   16848 use v5.26;
  12         89  
5 12     12   82 use strict;
  12         28  
  12         465  
6 12     12   64 use warnings;
  12         42  
  12         2863  
7 12     12   140 use warnings qw( FATAL utf8 );
  12         42  
  12         808  
8 12     12   133 use utf8;
  12         27  
  12         128  
9 12     12   520 use open qw( :std :utf8 );
  12         26  
  12         146  
10 12     12   2270 use Unicode::Normalize qw( NFC );
  12         40  
  12         1043  
11 12     12   115 use Unicode::Collate;
  12         170  
  12         445  
12 12     12   60 use Encode qw( decode );
  12         58  
  12         4940  
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 12     12   148 use autodie;
  12         28  
  12         128  
24 12     12   91694 use Carp qw( carp croak confess cluck );
  12         100  
  12         1695  
25 12     12   114 use English qw( -no_match_vars );
  12         29  
  12         133  
26 12     12   8945 use Data::Dumper qw( Dumper );
  12         31  
  12         3707  
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 12     12   113 use parent qw( Pg::SQL::PrettyPrinter::Node );
  12         26  
  12         127  
44              
45             sub new {
46 337     337 1 10990 my $class = shift;
47 337         1194 my $self = $class->SUPER::new( @_ );
48 337         645 bless $self, $class;
49 337         1176 $self->objectify( 'val' );
50 337         831 return $self;
51             }
52              
53             sub as_text {
54 481     481 1 764 my $self = shift;
55 481 100       1362 if ( exists $self->{ 'ival' } ) {
56 2   50     14 return $self->{ 'ival' }->{ 'ival' } // 0;
57             }
58 479 50       1334 if ( $self->{ 'isnull' } ) {
59 0         0 return 'NULL';
60             }
61 479 100       1032 if ( exists $self->{ 'sval' } ) {
62 1   50     15 return $self->quote_literal( $self->{ 'sval' }->{ 'sval' } // '' );
63             }
64 478 50       1071 if ( exists $self->{ 'boolval' } ) {
65 0 0       0 return $self->{ 'boolval' }->{ 'boolval' } ? 'true' : 'false';
66             }
67 478         1443 return $self->{ 'val' }->as_text;
68             }
69              
70             sub pretty_print {
71 179     179 1 310 my $self = shift;
72 179 100       464 if ( exists $self->{ 'ival' } ) {
73 2   50     17 return $self->{ 'ival' }->{ 'ival' } // 0;
74             }
75 177 50       392 if ( $self->{ 'isnull' } ) {
76 0         0 return 'NULL';
77             }
78 177 100       487 if ( exists $self->{ 'sval' } ) {
79 1   50     14 return $self->quote_literal( $self->{ 'sval' }->{ 'sval' } // '' );
80             }
81 176 50       386 if ( exists $self->{ 'boolval' } ) {
82 0 0       0 return $self->{ 'boolval' }->{ 'boolval' } ? 'true' : 'false';
83             }
84 176         614 return $self->{ 'val' }->pretty_print;
85             }
86              
87             1;