File Coverage

blib/lib/Pg/SQL/PrettyPrinter/Node/LockingClause.pm
Criterion Covered Total %
statement 59 59 100.0
branch 8 10 80.0
condition n/a
subroutine 16 16 100.0
pod 2 2 100.0
total 85 87 97.7


line stmt bran cond sub pod time code
1             package Pg::SQL::PrettyPrinter::Node::LockingClause;
2              
3             # UTF8 boilerplace, per http://stackoverflow.com/questions/6162484/why-does-modern-perl-avoid-utf-8-by-default/
4 3     3   4198 use v5.26;
  3         31  
5 3     3   29 use strict;
  3         14  
  3         75  
6 3     3   14 use warnings;
  3         5  
  3         203  
7 3     3   17 use warnings qw( FATAL utf8 );
  3         6  
  3         128  
8 3     3   15 use utf8;
  3         16  
  3         20  
9 3     3   97 use open qw( :std :utf8 );
  3         5  
  3         17  
10 3     3   385 use Unicode::Normalize qw( NFC );
  3         5  
  3         178  
11 3     3   51 use Unicode::Collate;
  3         73  
  3         176  
12 3     3   16 use Encode qw( decode );
  3         5  
  3         487  
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 3     3   19 use autodie;
  3         6  
  3         40  
24 3     3   14191 use Carp qw( carp croak confess cluck );
  3         6  
  3         252  
25 3     3   18 use English qw( -no_match_vars );
  3         11  
  3         23  
26 3     3   1189 use Data::Dumper qw( Dumper );
  3         6  
  3         741  
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 3     3   22 use parent qw( Pg::SQL::PrettyPrinter::Node );
  3         8  
  3         23  
44              
45             sub new {
46 10     10 1 251 my $class = shift;
47 10         32 my $self = $class->SUPER::new( @_ );
48 10         18 bless $self, $class;
49              
50 10 50       56 croak( 'Unknown strength of LockingClause ' . $self->{ 'strength' } ) unless $self->{ 'strength' } =~ m{\ALCS_FOR(?:KEYSHARE|NOKEYUPDATE|SHARE|UPDATE)\z};
51 10 50       39 croak( 'Unknown wait policy of LockingClause ' . $self->{ 'waitPolicy' } ) unless $self->{ 'waitPolicy' } =~ m{\ALockWait(?:Block|Error|Skip)\z};
52              
53 10         35 $self->objectify( 'lockedRels' );
54              
55 10         20 return $self;
56             }
57              
58             sub as_text {
59 20     20 1 25 my $self = shift;
60 20         30 my @parts = ( 'FOR' );
61             push @parts, {
62             LCS_FORUPDATE => 'UPDATE',
63             LCS_FORNOKEYUPDATE => 'NO KEY UPDATE',
64             LCS_FORSHARE => 'SHARE',
65             LCS_FORKEYSHARE => 'KEY SHARE'
66 20         92 }->{ $self->{ 'strength' } };
67              
68 20 100       62 if ( exists $self->{ 'lockedRels' } ) {
69 8         11 push @parts, 'OF ' . join( ', ', map { $_->as_text } @{ $self->{ 'lockedRels' } } );
  10         14  
  8         27  
70             }
71 20 100       49 if ( $self->{ 'waitPolicy' } eq 'LockWaitError' ) {
    100          
72 4         7 push @parts, 'NOWAIT';
73             }
74             elsif ( $self->{ 'waitPolicy' } eq 'LockWaitSkip' ) {
75 4         6 push @parts, 'SKIP LOCKED';
76             }
77 20         71 return join( ' ', @parts );
78             }
79              
80             1;
81              
82             # vim: set ft=perl: