line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UUID::Generator::PurePerl::NodeID; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
549
|
use strict; |
|
10
|
|
|
|
|
12
|
|
|
10
|
|
|
|
|
241
|
|
4
|
10
|
|
|
10
|
|
36
|
use warnings; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
205
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
31
|
use Carp; |
|
10
|
|
|
|
|
11
|
|
|
10
|
|
|
|
|
547
|
|
7
|
10
|
|
|
10
|
|
464
|
use POSIX ;#qw( uname ); |
|
10
|
|
|
|
|
5318
|
|
|
10
|
|
|
|
|
59
|
|
8
|
10
|
|
|
10
|
|
16205
|
use Digest; |
|
10
|
|
|
|
|
483
|
|
|
10
|
|
|
|
|
192
|
|
9
|
10
|
|
|
10
|
|
474
|
use Time::HiRes; |
|
10
|
|
|
|
|
1071
|
|
|
10
|
|
|
|
|
92
|
|
10
|
10
|
|
|
10
|
|
1017
|
use UUID::Generator::PurePerl::RNG; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
217
|
|
11
|
10
|
|
|
10
|
|
3753
|
use UUID::Generator::PurePerl::Util; |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
4247
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $USE_RANDOM_FACTOR_FOR_PSEUDO_NODE = 1; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $singleton; |
16
|
|
|
|
|
|
|
sub singleton { |
17
|
3
|
|
|
3
|
0
|
5
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
3
|
50
|
|
|
|
8
|
if (! defined $singleton) { |
20
|
3
|
|
|
|
|
10
|
$singleton = $class->new(); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
6
|
return $singleton; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
4
|
|
|
4
|
0
|
436
|
my $class = shift; |
28
|
4
|
|
|
|
|
8
|
my $self = bless {}, $class; |
29
|
|
|
|
|
|
|
|
30
|
4
|
50
|
|
|
|
12
|
if (@_) { |
31
|
0
|
|
|
|
|
0
|
$self->{use_rand} = shift; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
8
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub node_id { |
38
|
14
|
|
|
14
|
0
|
42
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
14
|
|
|
|
|
24
|
return $self->pseudo_node_id(0); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub physical_node_id { |
44
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub pseudo_node_id { |
50
|
26
|
|
|
26
|
0
|
2731
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
26
|
|
|
|
|
25
|
my $use_rand = shift; |
53
|
26
|
50
|
|
|
|
48
|
if (! defined $use_rand) { |
54
|
0
|
0
|
|
|
|
0
|
$use_rand = $self->{use_rand} if ref $self; |
55
|
0
|
0
|
|
|
|
0
|
if (! defined $use_rand) { |
56
|
0
|
|
|
|
|
0
|
$use_rand = $USE_RANDOM_FACTOR_FOR_PSEUDO_NODE; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
26
|
|
|
|
|
89
|
my $id = digest_as_octets(6, $self->_pseudo_node_source($use_rand)); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# set MSB |
63
|
26
|
|
|
|
|
39
|
substr $id, 0, 1, chr(ord(substr($id, 0, 1)) | 0x80); |
64
|
|
|
|
|
|
|
|
65
|
26
|
|
|
|
|
96
|
return $id; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub random_node_id { |
69
|
6
|
|
|
6
|
0
|
1282
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
6
|
100
|
|
|
|
20
|
if (! defined $self->{rng}) { |
72
|
1
|
|
|
|
|
3
|
my $seed = digest_as_32bit($self->_pseudo_node_source(1)); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
8
|
my $rng = UUID::Generator::PurePerl::RNG->new($seed); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
$self->{rng} = $rng; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
12
|
my $r1 = $self->{rng}->rand_32bit; |
80
|
6
|
|
|
|
|
12
|
my $r2 = $self->{rng}->rand_32bit; |
81
|
|
|
|
|
|
|
|
82
|
6
|
|
|
|
|
7
|
my $hi = ($r1 >> 8) ^ ($r2 & 0xff); |
83
|
6
|
|
|
|
|
7
|
my $lo = ($r2 >> 8) ^ ($r1 & 0xff); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# set MSB |
86
|
6
|
|
|
|
|
3
|
$hi |= 0x80; |
87
|
|
|
|
|
|
|
|
88
|
6
|
|
|
|
|
16
|
my $id = substr pack('V', $hi), 0, 3; |
89
|
6
|
|
|
|
|
10
|
$id .= substr pack('V', $lo), 0, 3; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
## set MSB |
92
|
|
|
|
|
|
|
#substr $id, 0, 1, chr(ord(substr($r, 0, 1)) | 0x80); |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
|
|
|
7
|
return $id; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _pseudo_node_source { |
98
|
27
|
|
|
27
|
|
31
|
my ($class, $use_rand) = @_; |
99
|
|
|
|
|
|
|
|
100
|
27
|
|
|
|
|
25
|
my @r; |
101
|
|
|
|
|
|
|
|
102
|
27
|
100
|
|
|
|
91
|
push @r, q{} . Time::HiRes::time() if $use_rand; |
103
|
27
|
100
|
|
|
|
44
|
push @r, q{:} . $$ if $use_rand; |
104
|
27
|
|
|
|
|
174
|
push @r, join(q{:}, POSIX::uname()); |
105
|
|
|
|
|
|
|
|
106
|
27
|
50
|
|
|
|
124
|
return wantarray ? @r : join q{}, @r; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |