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   8645 use v5.26;
  12         43  
5 12     12   55 use strict;
  12         18  
  12         337  
6 12     12   49 use warnings;
  12         19  
  12         609  
7 12     12   51 use warnings qw( FATAL utf8 );
  12         19  
  12         590  
8 12     12   52 use utf8;
  12         18  
  12         80  
9 12     12   367 use open qw( :std :utf8 );
  12         49  
  12         73  
10 12     12   1518 use Unicode::Normalize qw( NFC );
  12         19  
  12         605  
11 12     12   79 use Unicode::Collate;
  12         50  
  12         348  
12 12     12   99 use Encode qw( decode );
  12         20  
  12         1383  
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   88 use autodie;
  12         18  
  12         139  
24 12     12   47381 use Carp qw( carp croak confess cluck );
  12         18  
  12         905  
25 12     12   62 use English qw( -no_match_vars );
  12         17  
  12         71  
26 12     12   3587 use Data::Dumper qw( Dumper );
  12         20  
  12         2252  
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   114 use parent qw( Pg::SQL::PrettyPrinter::Node );
  12         16  
  12         72  
44              
45             sub new {
46 337     337 1 6954 my $class = shift;
47 337         800 my $self = $class->SUPER::new( @_ );
48 337         484 bless $self, $class;
49 337         876 $self->objectify( 'val' );
50 337         600 return $self;
51             }
52              
53             sub as_text {
54 481     481 1 591 my $self = shift;
55 481 100       893 if ( exists $self->{ 'ival' } ) {
56 2   50     7 return $self->{ 'ival' }->{ 'ival' } // 0;
57             }
58 479 50       845 if ( $self->{ 'isnull' } ) {
59 0         0 return 'NULL';
60             }
61 479 100       764 if ( exists $self->{ 'sval' } ) {
62 1   50     7 return $self->quote_literal( $self->{ 'sval' }->{ 'sval' } // '' );
63             }
64 478 50       840 if ( exists $self->{ 'boolval' } ) {
65 0 0       0 return $self->{ 'boolval' }->{ 'boolval' } ? 'true' : 'false';
66             }
67 478         969 return $self->{ 'val' }->as_text;
68             }
69              
70             sub pretty_print {
71 179     179 1 208 my $self = shift;
72 179 100       317 if ( exists $self->{ 'ival' } ) {
73 2   50     7 return $self->{ 'ival' }->{ 'ival' } // 0;
74             }
75 177 50       330 if ( $self->{ 'isnull' } ) {
76 0         0 return 'NULL';
77             }
78 177 100       271 if ( exists $self->{ 'sval' } ) {
79 1   50     5 return $self->quote_literal( $self->{ 'sval' }->{ 'sval' } // '' );
80             }
81 176 50       287 if ( exists $self->{ 'boolval' } ) {
82 0 0       0 return $self->{ 'boolval' }->{ 'boolval' } ? 'true' : 'false';
83             }
84 176         405 return $self->{ 'val' }->pretty_print;
85             }
86              
87             1;