File: Secure.pm

package info (click to toggle)
libobject-insideout-perl 4.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 892 kB
  • sloc: perl: 4,942; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (2)
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
package Object::InsideOut::Secure; {
    use strict;
    use warnings;
    use Config;

    our $VERSION = '4.05';
    $VERSION = eval $VERSION;

    use Object::InsideOut 4.05 ':hash_only';

    # Holds used IDs
    my %used :Field = ( 0 => undef );

    # Our PRNG
    BEGIN {
        $Math::Random::MT::Auto::shared = ($Config::Config{useithreads} &&
                                           $threads::shared::threads_shared);
    }
    use Math::Random::MT::Auto 5.04 ':!auto';
    my $prng = Math::Random::MT::Auto->new();

    # Assigns random IDs
    sub _id :ID
    {
        my $id;
        while (exists($used{$id = $prng->irand()})) {}
        $used{$id} = undef;
        return $id;
    }
}

1;

# EOF