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 3     3   7082 use v5.26;
  3         13  
4 3     3   22 use strict;
  3         7  
  3         92  
5 3     3   13 use warnings;
  3         10  
  3         298  
6 3     3   20 use warnings qw( FATAL utf8 );
  3         5  
  3         175  
7 3     3   19 use utf8;
  3         7  
  3         27  
8 3     3   151 use open qw( :std :utf8 );
  3         7  
  3         24  
9 3     3   602 use Unicode::Normalize qw( NFC );
  3         6  
  3         307  
10 3     3   20 use Unicode::Collate;
  3         6  
  3         229  
11 3     3   39 use Encode qw( decode );
  3         14  
  3         652  
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 3     3   25 use autodie;
  3         6  
  3         30  
23 3     3   32446 use Carp qw( carp croak confess cluck );
  3         7  
  3         1990  
24 3     3   31 use English qw( -no_match_vars );
  3         7  
  3         74  
25 3     3   1791 use Data::Dumper qw( Dumper );
  3         7  
  3         1047  
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 3     3   30 use parent qw( Pg::SQL::PrettyPrinter::Node );
  3         12  
  3         30  
43              
44             sub new {
45 9     9 1 1067 my $class = shift;
46 9         29 my $self = $class->SUPER::new( @_ );
47 9         11 bless $self, $class;
48              
49 9         29 my $keys_exist = grep { exists $self->{ $_ } } qw( lidx uidx );
  18         40  
50 9 50       17 croak( "Can't handle zero-arg A_Indices" ) if 0 == $keys_exist;
51              
52 9         28 $self->objectify( qw( lidx uidx ) );
53              
54 9 100       52 if ( !$self->{ 'is_slice' } ) {
55 3 50       6 croak( "Invalid A_Indices: isn't slice, but doesn't contain uidx!" ) unless exists $self->{ 'uidx' };
56             }
57              
58 9         47 return $self;
59             }
60              
61             sub as_text {
62 9     9 1 10 my $self = shift;
63 9         12 my $lv = '';
64 9         10 my $uv = '';
65 9 100       19 $lv = $self->{ 'lidx' }->as_text if exists $self->{ 'lidx' };
66 9 100       34 $uv = $self->{ 'uidx' }->as_text if exists $self->{ 'uidx' };
67 9 100       18 if ( $self->{ 'is_slice' } ) {
68 6         38 return sprintf(
69             '[%s:%s]',
70             $lv,
71             $uv
72             );
73             }
74 3         12 return sprintf(
75             '[%s]',
76             $uv
77             );
78             }
79              
80             sub pretty_print {
81 9     9 1 11 my $self = shift;
82 9         12 my $lv = '';
83 9         10 my $uv = '';
84 9 100       20 $lv = $self->{ 'lidx' }->pretty_print if exists $self->{ 'lidx' };
85 9 100       24 $uv = $self->{ 'uidx' }->pretty_print if exists $self->{ 'uidx' };
86 9 100       25 if ( $self->{ 'is_slice' } ) {
87 6         49 return sprintf(
88             '[%s:%s]',
89             $lv,
90             $uv
91             );
92             }
93 3         11 return sprintf(
94             '[%s]',
95             $uv
96             );
97             }
98              
99             1;