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   5309 use v5.26;
  3         13  
4 3     3   23 use strict;
  3         4  
  3         84  
5 3     3   15 use warnings;
  3         5  
  3         195  
6 3     3   16 use warnings qw( FATAL utf8 );
  3         6  
  3         153  
7 3     3   17 use utf8;
  3         6  
  3         19  
8 3     3   157 use open qw( :std :utf8 );
  3         8  
  3         18  
9 3     3   510 use Unicode::Normalize qw( NFC );
  3         7  
  3         213  
10 3     3   18 use Unicode::Collate;
  3         6  
  3         205  
11 3     3   18 use Encode qw( decode );
  3         11  
  3         508  
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   18 use autodie;
  3         7  
  3         24  
23 3     3   15123 use Carp qw( carp croak confess cluck );
  3         5  
  3         260  
24 3     3   18 use English qw( -no_match_vars );
  3         5  
  3         22  
25 3     3   1147 use Data::Dumper qw( Dumper );
  3         7  
  3         734  
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   20 use parent qw( Pg::SQL::PrettyPrinter::Node );
  3         5  
  3         22  
43              
44             sub new {
45 9     9 1 155 my $class = shift;
46 9         21 my $self = $class->SUPER::new( @_ );
47 9         13 bless $self, $class;
48              
49 9         13 my $keys_exist = grep { exists $self->{ $_ } } qw( lidx uidx );
  18         33  
50 9 50       19 croak( "Can't handle zero-arg A_Indices" ) if 0 == $keys_exist;
51              
52 9         21 $self->objectify( qw( lidx uidx ) );
53              
54 9 100       48 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         41 return $self;
59             }
60              
61             sub as_text {
62 9     9 1 10 my $self = shift;
63 9         10 my $lv = '';
64 9         10 my $uv = '';
65 9 100       19 $lv = $self->{ 'lidx' }->as_text if exists $self->{ 'lidx' };
66 9 100       20 $uv = $self->{ 'uidx' }->as_text if exists $self->{ 'uidx' };
67 9 100       16 if ( $self->{ 'is_slice' } ) {
68 6         50 return sprintf(
69             '[%s:%s]',
70             $lv,
71             $uv
72             );
73             }
74 3         9 return sprintf(
75             '[%s]',
76             $uv
77             );
78             }
79              
80             sub pretty_print {
81 9     9 1 11 my $self = shift;
82 9         8 my $lv = '';
83 9         11 my $uv = '';
84 9 100       19 $lv = $self->{ 'lidx' }->pretty_print if exists $self->{ 'lidx' };
85 9 100       22 $uv = $self->{ 'uidx' }->pretty_print if exists $self->{ 'uidx' };
86 9 100       20 if ( $self->{ 'is_slice' } ) {
87 6         40 return sprintf(
88             '[%s:%s]',
89             $lv,
90             $uv
91             );
92             }
93 3         13 return sprintf(
94             '[%s]',
95             $uv
96             );
97             }
98              
99             1;