summaryrefslogtreecommitdiffstats
path: root/src/pl/plperl/expected/plperl_shared.out
blob: 464e22090c328b9cd92552f51ba5da21734eaef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- test plperl.on_plperl_init via the shared hash
-- (must be done before plperl is first used)
-- This test tests setting on_plperl_init before loading plperl
-- testing on_plperl_init gets run, and that it can alter %_SHARED
SET plperl.on_plperl_init = '$_SHARED{on_init} = 42';
-- test the shared hash
create function setme(key text, val text) returns void language plperl as $$

  my $key = shift;
  my $val = shift;
  $_SHARED{$key}= $val;

$$;
create function getme(key text) returns text language plperl as $$

  my $key = shift;
  return $_SHARED{$key};

$$;
select setme('ourkey','ourval');
 setme 
-------
 
(1 row)

select getme('ourkey');
 getme  
--------
 ourval
(1 row)

select getme('on_init');
 getme 
-------
 42
(1 row)

-- verify that we can use $_SHARED in strict mode
create or replace function perl_shared() returns int as $$
use strict;
my $val = $_SHARED{'stuff'};
$_SHARED{'stuff'} = '1';
return $val;
$$ language plperl;
select perl_shared();
 perl_shared 
-------------
            
(1 row)

select perl_shared();
 perl_shared 
-------------
           1
(1 row)