summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/dist/Storable/t/tied_store.t
blob: c657f950db183cedbc3709b856b34776ea7704c2 (plain) (blame)
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
57
58
59
60
61
62
63
64
#!./perl

sub BEGIN {
    unshift @INC, 't';
    unshift @INC, 't/compat' if $] < 5.006002;
    require Config; import Config;
    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
        print "1..0 # Skip: Storable was not built\n";
        exit 0;
    }
}

use Storable ();
use Test::More tests => 3;

our $f;

package TIED_HASH;

sub TIEHASH { bless({}, $_[0]) }

sub STORE {
	$f = Storable::freeze(\$_[2]);
	1;
}

package TIED_ARRAY;

sub TIEARRAY { bless({}, $_[0]) }

sub STORE {
	$f = Storable::freeze(\$_[2]);
	1;
}

package TIED_SCALAR;

sub TIESCALAR { bless({}, $_[0]) }

sub STORE {
	$f = Storable::freeze(\$_[1]);
	1;
}

package main;

my($s, @a, %h);
tie $s, "TIED_SCALAR";
tie @a, "TIED_ARRAY";
tie %h, "TIED_HASH";

$f = undef;
$s = 111;
is $f, Storable::freeze(\111);

$f = undef;
$a[3] = 222;
is $f, Storable::freeze(\222);

$f = undef;
$h{foo} = 333;
is $f, Storable::freeze(\333);

1;