Consistently use "superuser" instead of "super user"
[pgsql.git] / src / pl / plperl / plc_perlboot.pl
blob028c4cea6d12ffbcdd9c6535ff7c1da544718d54
2 # Copyright (c) 2021, PostgreSQL Global Development Group
4 # src/pl/plperl/plc_perlboot.pl
6 use strict;
7 use warnings;
9 use 5.008001;
10 use vars qw(%_SHARED $_TD);
12 PostgreSQL::InServer::Util::bootstrap();
14 # globals
16 sub ::is_array_ref
18 return ref($_[0]) =~ m/^(?:PostgreSQL::InServer::)?ARRAY$/;
21 sub ::encode_array_literal
23 my ($arg, $delim) = @_;
24 return $arg unless (::is_array_ref($arg));
25 $delim = ', ' unless defined $delim;
26 my $res = '';
27 foreach my $elem (@$arg)
29 $res .= $delim if length $res;
30 if (ref $elem)
32 $res .= ::encode_array_literal($elem, $delim);
34 elsif (defined $elem)
36 (my $str = $elem) =~ s/(["\\])/\\$1/g;
37 $res .= qq("$str");
39 else
41 $res .= 'NULL';
44 return qq({$res});
47 sub ::encode_array_constructor
49 my $arg = shift;
50 return ::quote_nullable($arg) unless ::is_array_ref($arg);
51 my $res = join ", ",
52 map { (ref $_) ? ::encode_array_constructor($_) : ::quote_nullable($_) }
53 @$arg;
54 return "ARRAY[$res]";
58 #<<< protect next line from perltidy so perlcritic annotation works
59 package PostgreSQL::InServer; ## no critic (RequireFilenameMatchesPackage)
60 #>>>
61 use strict;
62 use warnings;
64 sub plperl_warn
66 (my $msg = shift) =~ s/\(eval \d+\) //g;
67 chomp $msg;
68 &::elog(&::WARNING, $msg);
69 return;
71 $SIG{__WARN__} = \&plperl_warn;
73 sub plperl_die
75 (my $msg = shift) =~ s/\(eval \d+\) //g;
76 die $msg;
78 $SIG{__DIE__} = \&plperl_die;
80 sub mkfuncsrc
82 my ($name, $imports, $prolog, $src) = @_;
84 my $BEGIN = join "\n", map {
85 my $names = $imports->{$_} || [];
86 "$_->import(qw(@$names));"
87 } sort keys %$imports;
88 $BEGIN &&= "BEGIN { $BEGIN }";
90 return qq[ package main; sub { $BEGIN $prolog $src } ];
93 sub mkfunc
95 ## no critic (ProhibitNoStrict, ProhibitStringyEval);
96 no strict; # default to no strict for the eval
97 no warnings; # default to no warnings for the eval
98 my $ret = eval(mkfuncsrc(@_));
99 $@ =~ s/\(eval \d+\) //g if $@;
100 return $ret;
101 ## use critic
109 package PostgreSQL::InServer::ARRAY;
110 use strict;
111 use warnings;
113 use overload
114 '""' => \&to_str,
115 '@{}' => \&to_arr;
117 sub to_str
119 my $self = shift;
120 return ::encode_typed_literal($self->{'array'}, $self->{'typeoid'});
123 sub to_arr
125 return shift->{'array'};