| 1 | package Pg::SQL::PrettyPrinter::Node::A_Indices; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use v5.26; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use warnings qw( FATAL utf8 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use open qw( :std :utf8 ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use Unicode::Normalize qw( NFC ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Unicode::Collate; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Encode qw( decode ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 3 | ▶ | if ( grep /\P{ASCII}/ => @ARGV ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | @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 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 3 | ▶ | use Carp qw( carp croak confess cluck ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 3 | ▶ | use English qw( -no_match_vars ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 3 | ▶ | use Data::Dumper qw( Dumper ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | # give a full stack dump on any untrapped exceptions | ||||||||||
| 28 | 0 | ▶ | local $SIG{ __DIE__ } = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 29 | 0 | ▶ | confess "Uncaught exception: @_" unless $^S; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 3 | }; | |||||||||
| 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 | 0 | ▶ | local $SIG{ __WARN__ } = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 36 | 0 | ▶ | if ( $^S ) { cluck "Trapped warning: @_" } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | else { confess "Deadly warning: @_" } | |||||||||
| 38 | 3 | }; | |||||||||
| 39 | |||||||||||
| 40 | # Useful common code | ||||||||||
| 41 | |||||||||||
| 42 | 3 | ▶ | use parent qw( Pg::SQL::PrettyPrinter::Node ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | 9 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 45 | 9 | my $class = shift; | |||||||||
| 46 | 9 | my $self = $class->SUPER::new( @_ ); | |||||||||
| 47 | 9 | bless $self, $class; | |||||||||
| 48 | |||||||||||
| 49 | 9 | my $keys_exist = grep { exists $self->{ $_ } } qw( lidx uidx ); | |||||||||
| 50 | 9 | ▶ | croak( "Can't handle zero-arg A_Indices" ) if 0 == $keys_exist; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 9 | $self->objectify( qw( lidx uidx ) ); | |||||||||
| 53 | |||||||||||
| 54 | 9 | ▶ | if ( !$self->{ 'is_slice' } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 3 | ▶ | croak( "Invalid A_Indices: isn't slice, but doesn't contain uidx!" ) unless exists $self->{ 'uidx' }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 9 | return $self; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 9 | ▶ | sub as_text { | ||||||||
|
Subroutine
as_text: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 62 | 9 | my $self = shift; | |||||||||
| 63 | 9 | my $lv = ''; | |||||||||
| 64 | 9 | my $uv = ''; | |||||||||
| 65 | 9 | ▶ | $lv = $self->{ 'lidx' }->as_text if exists $self->{ 'lidx' }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 9 | ▶ | $uv = $self->{ 'uidx' }->as_text if exists $self->{ 'uidx' }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 9 | ▶ | if ( $self->{ 'is_slice' } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 6 | return sprintf( | |||||||||
| 69 | '[%s:%s]', | ||||||||||
| 70 | $lv, | ||||||||||
| 71 | $uv | ||||||||||
| 72 | ); | ||||||||||
| 73 | } | ||||||||||
| 74 | 3 | return sprintf( | |||||||||
| 75 | '[%s]', | ||||||||||
| 76 | $uv | ||||||||||
| 77 | ); | ||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 9 | ▶ | sub pretty_print { | ||||||||
|
Subroutine
pretty_print: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 81 | 9 | my $self = shift; | |||||||||
| 82 | 9 | my $lv = ''; | |||||||||
| 83 | 9 | my $uv = ''; | |||||||||
| 84 | 9 | ▶ | $lv = $self->{ 'lidx' }->pretty_print if exists $self->{ 'lidx' }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 9 | ▶ | $uv = $self->{ 'uidx' }->pretty_print if exists $self->{ 'uidx' }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 9 | ▶ | if ( $self->{ 'is_slice' } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 6 | return sprintf( | |||||||||
| 88 | '[%s:%s]', | ||||||||||
| 89 | $lv, | ||||||||||
| 90 | $uv | ||||||||||
| 91 | ); | ||||||||||
| 92 | } | ||||||||||
| 93 | 3 | return sprintf( | |||||||||
| 94 | '[%s]', | ||||||||||
| 95 | $uv | ||||||||||
| 96 | ); | ||||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 3 | 1; | |||||||||