2 # Copyright (c) 2021-2024, PostgreSQL Global Development Group
4 # src/pl/plperl/plc_perlboot.pl
7 use warnings FATAL
=> 'all';
9 use vars
qw(%_SHARED $_TD);
11 PostgreSQL::InServer::Util::bootstrap();
17 return ref($_[0]) =~ m/^(?:PostgreSQL::InServer::)?ARRAY$/;
20 sub ::encode_array_literal
22 my ($arg, $delim) = @_;
23 return $arg unless (::is_array_ref($arg));
24 $delim = ', ' unless defined $delim;
26 foreach my $elem (@$arg)
28 $res .= $delim if length $res;
31 $res .= ::encode_array_literal($elem, $delim);
35 (my $str = $elem) =~ s/(["\\])/\\$1/g;
46 sub ::encode_array_constructor
49 return ::quote_nullable($arg) unless ::is_array_ref($arg);
51 map { (ref $_) ? ::encode_array_constructor($_) : ::quote_nullable($_) }
57 #<<< protect next line from perltidy so perlcritic annotation works
58 package PostgreSQL::InServer; ## no critic (RequireFilenameMatchesPackage)
61 use warnings FATAL => 'all';
65 (my $msg = shift) =~ s/\(eval \d+\) //g;
67 &::elog(&::WARNING, $msg);
70 $SIG{__WARN__} = \&plperl_warn;
74 (my $msg = shift) =~ s/\(eval \d+\) //g;
77 $SIG{__DIE__} = \&plperl_die;
81 my ($name, $imports, $prolog, $src) = @_;
83 my $BEGIN = join "\n", map {
84 my $names = $imports->{$_} || [];
85 "$_->import(qw(@$names));"
86 } sort keys %$imports;
87 $BEGIN &&= "BEGIN { $BEGIN }";
89 return qq[ package main; sub { $BEGIN $prolog $src } ];
94 ## no critic (ProhibitNoStrict, ProhibitStringyEval);
95 no strict; # default to no strict for the eval
96 no warnings; # default to no warnings for the eval
97 my $ret = eval(mkfuncsrc(@_));
98 $@ =~ s/\(eval \d+\) //g if $@;
108 package PostgreSQL::InServer::ARRAY;
110 use warnings FATAL => 'all';
119 return ::encode_typed_literal($self->{'array'}, $self->{'typeoid'});
124 return shift->{'array'};