line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SimpleFlake; |
2
|
5
|
|
|
5
|
|
64299
|
use 5.008001; |
|
5
|
|
|
|
|
19
|
|
3
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
111
|
|
4
|
5
|
|
|
5
|
|
33
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
168
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
4311
|
use Time::HiRes qw(time); |
|
5
|
|
|
|
|
7489
|
|
|
5
|
|
|
|
|
22
|
|
7
|
5
|
|
|
5
|
|
10458449
|
use Math::BigInt lib => 'GMP'; |
|
5
|
|
|
|
|
133598
|
|
|
5
|
|
|
|
|
29
|
|
8
|
5
|
|
|
|
|
1844
|
use Bytes::Random::Secure qw( |
9
|
|
|
|
|
|
|
random_bytes random_bytes_base64 random_bytes_hex |
10
|
5
|
|
|
5
|
|
607079
|
); |
|
5
|
|
|
|
|
920598
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $random; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub random { |
17
|
|
|
|
|
|
|
|
18
|
100002
|
|
|
100002
|
0
|
126208
|
my ($class) = @_; |
19
|
|
|
|
|
|
|
|
20
|
100002
|
100
|
|
|
|
212280
|
unless ($random) { |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
72
|
$random = Bytes::Random::Secure->new( |
23
|
|
|
|
|
|
|
Bits => 64, |
24
|
|
|
|
|
|
|
NonBlocking => 1, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
100002
|
|
|
|
|
313238
|
return $random; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_random_bits { |
32
|
|
|
|
|
|
|
|
33
|
100002
|
|
|
100002
|
0
|
152082
|
my ( $class, $length ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
100002
|
|
|
|
|
221499
|
my $return = Math::BigInt->from_bin( unpack( 'B*', $class->random->bytes(2) ) ); |
36
|
|
|
|
|
|
|
|
37
|
100002
|
|
|
|
|
10519531
|
return $return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_millisecond_timestamp { |
41
|
|
|
|
|
|
|
|
42
|
100002
|
|
|
100002
|
0
|
121034
|
my $epoch = 946702800; |
43
|
|
|
|
|
|
|
|
44
|
100002
|
|
|
|
|
431803
|
my $time = Math::BigInt->new( int( ( time - $epoch ) * 1_000_000 ) ); |
45
|
100002
|
|
|
|
|
3136574
|
return $time; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_flake { |
49
|
|
|
|
|
|
|
|
50
|
100001
|
|
|
100001
|
0
|
14994685
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
100001
|
|
|
|
|
200735
|
my $timestamp = $self->get_millisecond_timestamp; |
53
|
100001
|
|
|
|
|
223763
|
my $random = $self->get_random_bits; |
54
|
|
|
|
|
|
|
|
55
|
100001
|
|
|
|
|
274205
|
my $flake = $timestamp->blsft(15); |
56
|
100001
|
|
|
|
|
18378069
|
$flake->bior($random); |
57
|
|
|
|
|
|
|
|
58
|
100001
|
|
|
|
|
17131531
|
return substr( $flake->as_hex, 2 ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |