File: destroy.t

package info (click to toggle)
libobject-id-perl 0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 176 kB
  • ctags: 9
  • sloc: perl: 291; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 750 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

# Ensure that a class having a DESTROY method does not interfere
# Ensure objects with the same ref still get different IDs.

use strict;
use warnings;

use Test::More;

{
    package My::Class;
    use Object::ID;

    sub new {
        my $class = shift;
        my $ref   = shift;

        bless $ref, $class;
    }

    my $Destroyed;
    sub destroy_called {
        return $Destroyed;
    }

    sub DESTROY {
        $Destroyed++;
    }
}


{
    my %ids;
    for(1..3) {
        my $obj = new_ok "My::Class", [{}];
        $ids{$obj->object_id}++;
    }

    is keys %ids, 3, "got different IDs for each object" or diag explain \%ids;
    is( My::Class->destroy_called, 3, "all three objects destroyed" );
}

done_testing();