File: 30_already_tied.t

package info (click to toggle)
libdbm-deep-perl 2.0008-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 884 kB
  • sloc: perl: 7,383; sql: 36
file content (80 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use strict;
use warnings FATAL => 'all';

use Test::More;
use Test::Exception;
use t::common qw( new_dbm );

use_ok( 'DBM::Deep' );

my $dbm_factory = new_dbm();
while ( my $dbm_maker = $dbm_factory->() ) {
    my $db = $dbm_maker->();

    {
        {
            package My::Tie::Hash;

            sub TIEHASH {
                my $class = shift;

                return bless {
                }, $class;
            }
        }

        my %hash;
        tie %hash, 'My::Tie::Hash';
        isa_ok( tied(%hash), 'My::Tie::Hash' );

        throws_ok {
            $db->{foo} = \%hash;
        } qr/Cannot store something that is tied/, "Cannot store tied hashes";
    }

    {
        {
            package My::Tie::Array;

            sub TIEARRAY {
                my $class = shift;

                return bless {
                }, $class;
            }

            sub FETCHSIZE { 0 }
        }

        my @array;
        tie @array, 'My::Tie::Array';
        isa_ok( tied(@array), 'My::Tie::Array' );

        throws_ok {
            $db->{foo} = \@array;
        } qr/Cannot store something that is tied/, "Cannot store tied arrays";
    }

    {
        {
            package My::Tie::Scalar;

            sub TIESCALAR {
                my $class = shift;

                return bless {
                }, $class;
            }
        }

        my $scalar;
        tie $scalar, 'My::Tie::Scalar';
        isa_ok( tied($scalar), 'My::Tie::Scalar' );

        throws_ok {
            $db->{foo} = \$scalar;
        } qr/Storage of references of type 'SCALAR' is not supported/, "Cannot store scalar references, let alone tied scalars";
    }
}

done_testing;