File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/A_Indices.pm
Criterion Covered Total %
statement 67 67 100.0
branch 16 18 88.8
condition n/a
subroutine 17 17 100.0
pod 3 3 100.0
total 103 105 98.1


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::A_Indices;
2              
3 2     2   1873 use v5.26;
  2         8  
4 2     2   21 use strict;
  2         4  
  2         50  
5 2     2   15 use warnings;
  2         4  
  2         58  
6 2     2   12 use warnings qw( FATAL utf8 );
  2         5  
  2         72  
7 2     2   11 use utf8;
  2         4  
  2         20  
8 2     2   68 use open qw( :std :utf8 );
  2         6  
  2         13  
9 2     2   270 use Unicode::Normalize qw( NFC );
  2         15  
  2         129  
10 2     2   16 use Unicode::Collate;
  2         6  
  2         68  
11 2     2   11 use Encode qw( decode );
  2         7  
  2         137  
12              
13             if ( grep /\P{ASCII}/ => @ARGV ) {
14             @ARGV = map { decode( 'UTF-8', $_ ) } @ARGV;
15             }
16              
17             # If there is __DATA__,then uncomment next line:
18             # binmode( DATA, ':encoding(UTF-8)' );
19             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
20              
21             # Useful common code
22 2     2   544 use autodie;
  2         6  
  2         12  
23 2     2   11482 use Carp qw( carp croak confess cluck );
  2         15  
  2         191  
24 2     2   24 use English qw( -no_match_vars );
  2         11  
  2         17  
25 2     2   775 use Data::Dumper qw( Dumper );
  2         11  
  2         539  
26              
27             # give a full stack dump on any untrapped exceptions
28             local $SIG{ __DIE__ } = sub {
29             confess "Uncaught exception: @_" unless $^S;
30             };
31              
32             # now promote run-time warnings into stackdumped exceptions
33             # *unless* we're in an try block, in which
34             # case just generate a clucking stackdump instead
35             local $SIG{ __WARN__ } = sub {
36             if ( $^S ) { cluck "Trapped warning: @_" }
37             else { confess "Deadly warning: @_" }
38             };
39              
40             # Useful common code
41              
42 2     2   17 use parent qw( Pg::SQL::PrettyPrinter::Node );
  2         6  
  2         13  
43              
44             sub new {
45 9     9 1 237 my $class = shift;
46 9         31 my $self = $class->SUPER::new( @_ );
47 9         17 bless $self, $class;
48              
49 9         21 my $keys_exist = grep { exists $self->{ $_ } } qw( lidx uidx );
  18         82  
50 9 50       26 croak( "Can't handle zero-arg A_Indices" ) if 0 == $keys_exist;
51              
52 9         34 $self->objectify( qw( lidx uidx ) );
53              
54 9 100       62 if ( !$self->{ 'is_slice' } ) {
55 3 50       7 croak( "Invalid A_Indices: isn't slice, but doesn't contain uidx!" ) unless exists $self->{ 'uidx' };
56             }
57              
58 9         63 return $self;
59             }
60              
61             sub as_text {
62 9     9 1 12 my $self = shift;
63 9         15 my $lv = '';
64 9         14 my $uv = '';
65 9 100       27 $lv = $self->{ 'lidx' }->as_text if exists $self->{ 'lidx' };
66 9 100       28 $uv = $self->{ 'uidx' }->as_text if exists $self->{ 'uidx' };
67 9 100       25 if ( $self->{ 'is_slice' } ) {
68 6         67 return sprintf(
69             '[%s:%s]',
70             $lv,
71             $uv
72             );
73             }
74 3         18 return sprintf(
75             '[%s]',
76             $uv
77             );
78             }
79              
80             sub pretty_print {
81 9     9 1 16 my $self = shift;
82 9         16 my $lv = '';
83 9         13 my $uv = '';
84 9 100       36 $lv = $self->{ 'lidx' }->pretty_print if exists $self->{ 'lidx' };
85 9 100       27 $uv = $self->{ 'uidx' }->pretty_print if exists $self->{ 'uidx' };
86 9 100       30 if ( $self->{ 'is_slice' } ) {
87 6         72 return sprintf(
88             '[%s:%s]',
89             $lv,
90             $uv
91             );
92             }
93 3         16 return sprintf(
94             '[%s]',
95             $uv
96             );
97             }
98              
99             1;